Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a function work on all players touching it instead of just 1?

Asked by 5 years ago

I made a script that's supposed to clone a small garden that is in ReplicatedStorage and place it on the player (That part isn't in the shown script). I want it to be when the garden is touched if they are not the player that made it then they take damage, and if they are then they get healed. Everything works correctly except the script will only affect one person at at time. So for example if the creator is in it getting healed and another player is inside it the creator will still get healed but the other player wont be detected. How do I allow it to detect both all players touching it at once.

GardenO.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if Humanoid.Parent == Character then
if deb == true then return end
deb = true
AlreadyTouched = true
print("Local Humanoid Touched")
Humanoid.Health = Humanoid.Health + 10
print ("Healed " ..Humanoid.Name.. " Once")
wait(1)
Humanoid.Health = Humanoid.Health + 10
print("Healed " ..Humanoid.Name.. " Twice")
wait(1)
Humanoid.Health = Humanoid.Health + 10
print("Healed " ..Humanoid.Name.. " Three Times")
wait(1)
Humanoid.Health = Humanoid.Health + 10
print("Healed " ..Humanoid.Name.. " Four Times")
wait(1)
Humanoid.Health = Humanoid.Health + 10
print("Healed " ..Humanoid.Name.. " Five Times")
else
if deb == true then return end
deb = true
Humanoid.Health = Humanoid.Health - 10
print ("Hurt " ..Humanoid.Name.. " Once")
wait(1)
Humanoid.Health = Humanoid.Health - 10
print("Hurt " ..Humanoid.Name.. " Twice")
wait(1)
Humanoid.Health = Humanoid.Health - 10
print("Hurt " ..Humanoid.Name.. " Three Times")
wait(1)
Humanoid.Health = Humanoid.Health - 10
print("Hurt " ..Humanoid.Name.. " Four Times")
wait(1)
Humanoid.Health = Humanoid.Health - 10
print("Hurt " ..Humanoid.Name.. " Five Times")
end
wait(5)
GardenO:Destroy()
deb = false
end)
wait(0.2)
Debounce = false
end)
0
Fix the indentation. Don't block it with a debounce for everyone, perhaps keep separate debounce values depending on player touching. gullet 471 — 5y
0
use a regular script instead of local. greatneil80 2647 — 5y
0
@greatneil80 this is a regular script and @gullet the indentation is normally correct it's just the new text thing they have for the website is broken. songboy50 77 — 5y
0
And @gullet I've already tried removing the debounce and although it does attack all players it attacks them millions of times, so instead of them taking a total of 50 damage they will take like 500,000 damage. songboy50 77 — 5y

Answer this question