Im using ZonePlus and trying to make it so player gets damaged when they are in a zone.
But my loop doesnt end if i leave the zone.
icebath.playerEntered:Connect(function(player)
print("player has entered the zone")
local isWithinZoneBool = icebath:findPlayer(player)
local health = game.Workspace:WaitForChild(player.Name).Humanoid
while true do
wait()
if isWithinZoneBool then
health.Health -= 15
wait(1)
elseif not isWithinZoneBool then
end
end
end)
You never refresh isWithinZoneBool. Also, the loop condition should be isWithinZoneBool.
icebath.playerEntered:Connect(function(player)
print("player has entered the zone")
local health = game.Workspace:WaitForChild(player.Name).Humanoid
while icebath:findPlayer(player) do
health.Health -= 15
task.wait(1)
end
end)
Ah yea the issue is that you don’t keep checking if the user is in the zone or not. You check once outside of the loop and then you just check the exact same thing over and over. Put the isWithinZoneBool inside of the while true loop.
Basically what @Kaid3n22 said but I don’t think it is explained very well how they put it because of them just saying that the variable is never refreshed which is not really the correct terminology in my option.