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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
| |
|
ForceSky
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
|
| 30 Nov 2013 04:38 PM |
| Can you explain how to 'call' the coroutines? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|