This code fires a script to damage the person who touches the poison cloud but when there are 2 poison clouds in workspace at the same time, it only works for one of the poison cloud (if you touch the first poison cloud made it works, if you touch the second poison cloud when the first poison cloud is still in workspace it doesn't work) Is there anyway to solve this?
local cooldown = false
local damageRemoteHolder = game:GetService("ReplicatedStorage")
local damageRemote = damageRemoteHolder:WaitForChild("PoisonBombDamage")
local poisonCloud = game.Workspace:WaitForChild("Poison") or game.Workspace:FindFirstChild("Poison")
poisonCloud.Touched:Connect(function(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) and (cooldown == false) and human.Parent.Name == script.Parent.Parent.Name then
cooldown = true
damageRemote:FireServer(script.Damage.Value, script.Parent.Parent.Character:FindFirstChild("Humanoid"))
wait(script.PoisonCooldown.Value)
cooldown = false
end
end)
I need to keep it a local script so that it stops damaging only 1 person when there are multiple people inside the poison cloud

3 comments
sorry, but this doesn't work
it doesn't damage it at all
I fixed the code you gave me, since it uses "for" it only searched for it once. So I put it in a "while wait() do" loop and now it works perfectly. Tysm!