so im making a game where it has some super powers like shooting fire balls and im having some problems with a hit function in the script. this is the hit part:
fireBall.Touched:Connect(function(hit) if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end if caster == player then game.ReplicatedStorage.Events.FireBall:FireServer(hit) end end)
this fires when the fireball hits a player. i want the fireball to carry on and damage everyone it touches without spamming the damage
i dont want to destroy teh fireball when it touches a player so if there is a group of people i want it to damage all of them. right now whats happening is that when it touches a player it damages them multiple times by firing many remotes. how would i stop it from doing that?
It's spamming because it is firing once for each of the body parts. I would suggest that you only listen for Touched events on the HumanoidRootPart.
fireBall.Touched:Connect(function(hit) if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end if caster == player and hit.Name == "HumanoidRootPart" then game.ReplicatedStorage.Events.FireBall:FireServer(hit) end end)
Using this solution, you might have the problem of exploiters changing the name of their HumanoidRootPart to avoid damage. This could be remedied with a routine check (every minute or so maybe) on every player's character to ensure nothing is out of the ordinary.
If you want the fireball to also damage when hitting other body parts, I would suggest you give each player a hitbox that stretches over their entire character, then listen for touched events on that.
You should add a debounce for example:
local debounce = false fireBall.Touched:Connect(function(hit) if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end if caster == player and not debounce then debounce = true game.ReplicatedStorage.Events.FireBall:FireServer(hit) end end)
However, this would make the fireball only hit once (to one player).
So if you wanted to make the fireball only damage people once, you would most likely have to create a table of players and insert the player name into it (when the player is hit), and only hit people who's name isnt in the table