What I’m trying to do is make it so that when a remote event is fired, it starts to slowly decrease the player’s health overtime. I have no idea why it’s not working. All help is appreciated! This is a server script in StarterCharacterScripts.
local enabled = false
game.ReplicatedStorage["207"].OnServerEvent:Connect(function()
enabled = true
print(enabled)
end)
while wait(1) do
print("Check")
if enabled == true then
script.Parent.Humanoid.Health -= 1
end
end
By testing this script, it works perfectly fine. The issue you seem to be facing is your health is regenerated automatically before your script can damage the humanoid further. This can be fixed by changing the wait interval (maybe try 0.5).
Also, it might be worth noting that coding the OnServerEvent function that way and having another player firing the remote event will result in the variable being changed to true for enabled for all players that have the script in their character.