Hello! this is my first post to the devforum as ive just been made a member which is pretty exciting
in any case ive run across a strange issue.
im in the process of writing a simple fireball script. right now the script just grabs the player’s hand CFrame and just clones it onto their hand. however, if the script is fired multiple times it clones one more duplicate fireball each time it is used.
eg: first time spawns one, second time spawns two, ect.
here is the code:
relevant code in the player’s localscript:
--the animation has a marker at the midpoint called "Cast", which is the point
--the fireball should be launched. the marker "End" is simply a marker at the
--last keyframe
uis.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if castingfireball == false then
if input.KeyCode == keybind then
castingfireball = true
animation:Play()
animation:GetMarkerReachedSignal("Cast"):Connect(function()
local handcframe = player.Character.RightHand.CFrame
fireballevent:FireServer(handcframe)
end)
animation:GetMarkerReachedSignal("End"):Connect(function()
animation:Stop()
castingfireball = false
end)
elseif castingfireball == true then return end
end
end)
and the serverscript that gets fired (as it is right now):
function firespell(player,handcframe)
local thefireball = AbilityAssets.Fireball.Fireball:Clone()
thefireball.Parent = game:GetService("Workspace")
thefireball:SetPrimaryPartCFrame(handcframe)
end
FireballEvent.OnServerEvent:Connect(firespell)
testing with console prints indicated that the server script is actually being fired multiple times, which only confused me even more. the animation plays just fine, and the localscript doesnt run any duplicate lines. so if anyone has any idea what might be causing this i would greatly appreciate any input.
also: sorry if i melted anyone’s eyes with that code. i am still learning so any bad habbits or optimizations anyone notices would also be great to hear about. thanks in advance!
You Can Use Debounce that can allow it to do it and I don’t know if the casting fireball is the debounce or not so I may be wrong but the error may be there your debounce