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
I dont know if this works as i haven't gotten to test it but give this a try and see if it works.
local cooldown = false local damageRemoteHolder = game:GetService("ReplicatedStorage") local damageRemote = damageRemoteHolder:WaitForChild("PoisonBombDamage") for i, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Poison" then poisonCloud = v 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) end end