generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Shotgun only shoots one ray?

Previous Thread :: Next Thread 
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 11:13 AM
I have this shotgun script. It uses a for loop to shoot multiple bullets at once. Value represents the ammo. When I shoot once, it should shoot six pellets and deduct one from value. Occasionally, the gun only shoots one bullet. I tried editing the script so it deducts one from value every time a pellet is fired. The value was deducted by six, but only one ray came out. Help please? I know it's kind of big, but I wasn't sure what was important.

local tool = script.Parent
local user = nil
local value = 6
local deb = false
tool.Equipped:connect(function(mouse)
print("Equipped")
user = tool.Parent
mouse.Icon = "rbxasset://textures\\GunCursor.png"
game.Players.LocalPlayer.PlayerGui.AmmoGui.Frame.TextLabel.Text = value
mouse.Button1Down:connect(function()
value = value - 1
print("Fire")
if deb == true then
return
end
if value == 0 then
return
end
deb = true
for x = 1, 6 do
game.Players.LocalPlayer.PlayerGui.AmmoGui.Frame.TextLabel.Text = value
local ray = Ray.new(tool.Shot.CFrame.p, (mouse.Hit.p - tool.Shot.CFrame.p).unit * 300)
local _, position = workspace:FindPartOnRay(ray, user)
local distance = (position - tool.Shot.CFrame.p).magnitude
local spread = 0.175 * distance
local ray2 = Ray.new(tool.Shot.CFrame.p, (mouse.Hit.p - tool.Shot.CFrame.p + Vector3.new(math.random(-spread, spread), math.random(-spread, spread), math.random(-spread, spread))).unit * 300)
local hit, position2 = workspace:FindPartOnRay(ray2, user)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Enemy")
if humanoid then
humanoid.Health = humanoid.Health - math.random(15, 18)
end
local desiredZ = (position2 - tool.Shot.CFrame.p).magnitude
local raypart = Instance.new("Part", Workspace)
raypart.Name = "Ray"
raypart.BrickColor = BrickColor.new("White")
raypart.Anchored = true
raypart.CanCollide = false
raypart.TopSurface = Enum.SurfaceType.Smooth
raypart.BottomSurface = Enum.SurfaceType.Smooth
raypart.FormFactor = Enum.FormFactor.Custom
raypart.Size = Vector3.new(0.2, 0.2, desiredZ)
raypart.CFrame = CFrame.new(position2, tool.Shot.CFrame.p) * CFrame.new(0, 0, -desiredZ/2)
game.Debris:AddItem(raypart, 0.05)
end
wait(1)
deb = false
end)
mouse.KeyDown:connect(function(key)
if key:lower() == "r" then
print("load")
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
wait(4)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
value = 6
game.Players.LocalPlayer.PlayerGui.AmmoGui.Frame.TextLabel.Text = value
end
end)
end)
tool.Unequipped:connect(function()
game.Players.LocalPlayer.PlayerGui.AmmoGui.Frame.TextLabel.Text = "N/A"
end)
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 12:49 PM
Bump.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 03:40 PM
Bump.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
30 Nov 2013 03:45 PM
try adding prints to see if it gets passed the second ray and also at the ends, where you can, add elseif's and use print
for ex:
if bob=me then
print('yes')
elseif bob~=me then
print('bob is not me:error')
end
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 04:09 PM
I've tried something like that, where for every pellet the ammo goes down one. The ammo says that there should be 6 rays firing, but there aren't.
Report Abuse
yoshimaster240102 is not online. yoshimaster240102
Joined: 14 Apr 2012
Total Posts: 470
30 Nov 2013 04:10 PM
Add a coroutine to each ray fire.

Example:

coroutine.resume(coroutine.create(function()
--Ray Stuff
end))
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 04:38 PM
Can you explain how to 'call' the coroutines?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
30 Nov 2013 04:39 PM
coroutine.resume which he did, or you could do

x = coroutine.wrap(function() ... end)
x()
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 04:45 PM
Thanks. How would I control how many times it activates?
Report Abuse
powertool is not online. powertool
Joined: 01 Feb 2008
Total Posts: 3771
30 Nov 2013 04:47 PM
Interesting, I'm busy with a shotgun script right now. What I did, was I used a while ammo > 0 and blast <= 9 do loop, and I had it run through a raycast function, but using FindPartOnRayWithIgnoreList.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image