The first time the function runs is 1, then its 2, then 3 ect, at the same time. I cant seem to figure out why exactly it is doing this. It is causing the script to error as the item is deleted the first run.
Code:
local Event = Explode.Event:Connect(function()
for Index, Bloon in ipairs(game.Workspace.Bloons:GetChildren()) do
if Bloon:FindFirstChild("Humanoid").Health > 0 then
local Mag = (Projectile.PrimaryPart.Position - Bloon.PrimaryPart.Position).Magnitude
if Mag < Stat.BlastRange then
Bloon:FindFirstChild("Humanoid").Health = Bloon:FindFirstChild("Humanoid").Health - Stat.Dmg
end
end
end
end)
local Detonate = script.Parent
local Explode = game.ServerScriptService.Events.Explode
Detonate.Touched:Connect(function()
Detonate.Anchored = true
Detonate.CanCollide = false
local Boom = game.ServerStorage.Objects.Impact:Clone()
Boom.Parent = Detonate
--print("Event Sent")
Explode:Fire()
end)
In all likelihood it is a debounce issue. An event signals multiple times and thus the bindable event triggers multiple times. Find a way to prevent the multitrigger from/by the root source
This was a necro-post. The solution was that the event was being connected several times to the same object because I was not disconnecting the event.
If I remember this code correctly considering I wrote this well over 4 years ago, I believe Explode was not a clone. Also note Detonate was not a clone. Each had events connected several times which caused the added effect. If you run this experiment, it would follow the logic of 2’s, 2 ^ 0, 2 ^ 1, then 2 ^ 0 + 2 ^ 1, then logically it would follow 2 ^ 2, 2 ^ 2 + 2 ^ 1, ect…
I do not make mistakes like this anymore, the errors I run into now are purely logical or lua runtime/compilation errors.