wait() script.Parent.OnServerEvent:Connect(function(player,mh) local fire2 = script.Parent.Parent.FlameBulletsE.Script.Fire2.Value local fire3 = script.Fire3.Value if fire2 == true then local clone = script.Parent.Parent.FlameBulletsE.Script:Clone() script.Parent.Parent.FlameBulletsE.Script.Disabled = true clone.Parent = script.Parent.Parent.FlameBulletsE script.Parent.Parent.FlameBulletsE.Script:Destroy() fire2 = false end local character = player.Character local fire = script.Parent.Parent.FlameBulletsE.Script.Fire.Value local debounce = false if character.HumanoidRootPart:FindFirstChild("Bodg") ~= nil then character.HumanoidRootPart:FindFirstChild("Bodg"):Destroy() local bg = Instance.new("BodyGyro",character.HumanoidRootPart) bg.Name = "Bodg" bg.P = 10000 bg.MaxTorque = Vector3.new(99999,99999,99999) bg.CFrame = mh local fb = game.ReplicatedStorage.Objects.FlameBullet:Clone() fb.Parent = workspace if debounce == false then debounce = true fb.CFrame = character.RightHand.CFrame elseif debounce == true then debounce = false fb.CFrame = character.LeftHand.CFrame end local fv = Instance.new("BodyVelocity",fb) fv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) fv.Velocity = mh.LookVector * 100 game.Debris:AddItem(fb,2) end end)
The event is rapidly being fired which means a lot of these so called fireballs are being shot. Their starting points should alternate between the right and the left hand CFrames as stated in lines 42 and 47, but it doesn't happen. I have tried various things but none changed the result. The starting position is always the right hand CFrame instead of it changing from the right hand to the left hand one. Any ideas on how to fix this issue?
I don't know if this is intentional, but, your issue might be with how you state the "if, elseif" statement. Remember, when we run an if statement, when that if statement is true, it runs that code, and then moves on to the next chunk, in this case "fv". That's why it ignores elseif, since the original if ran perfectly fine, therefore elseif doesn't need to be called. Try switching to this:
local debounce = true --Outside Of The Function if debounce == true then fb.CFrame = character.RightHand.CFrame debounce = false elseif debounce == false then fb.CFrame = character.LeftHand.CFrame debounce = true end
Hope This Helped!
If not, please comment.
I see that you already found the problem in your example, which was initializing your boolean state on every event, such that it was always false. But, for the sake of readability and efficiency, consider also replacing this structure:
local debounce = false ... if debounce == false then debounce = true fb.CFrame = character.RightHand.CFrame elseif debounce == true then debounce = false fb.CFrame = character.LeftHand.CFrame end
with something more like this:
local useLeft = true ... if useLeft then fb.CFrame = character.LeftHand.CFrame else fb.CFrame = character.RightHand.CFrame end useLeft = not useLeft
or the more compact Lua quasi-ternary-conditional pattern:
local useLeft = true ... fb.CFrame = useLeft and character.LeftHand.CFrame or character.RightHand.CFrame useLeft = not useLeft
The distinctions from your original code are: