I want this script to do so when a player is touching the Fire, the player will take damage until the player isnt touching the Fire anymore.
What is the issue?
The player still takes damage after not touching the Fire anymore
What solutions have you tried so far?
I have tried a lot of combinations, but none of them worked
local Fire = script.Parent
Fire.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then
while true do
print("Burning")
hit.Parent.Humanoid.Health += -1
wait(0.1)
if Fire.TouchEnded == true then
break
end
end
end
end)
TouchEnded, like Touched, is an event that roblox fires whenever the player stops touching a BasePart. You need to treat it just like you treated the .Touched event, using the :Connect() method. I would have the .TouchEnded event change a boolean variable to true, and then when that boolean variable is true break out of your while loop.
You know the while true do is not worth it since what you should use is takedamage and also I’m going to pass you a script
Please wait
I’m going to open the studio
local zona = script.Parent
zona.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(0.1)
end
end)