Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Decrease health forever not working?

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

1 answer

maybe try putting script into the serverscriptservice or workspace and then do that

game.Players.PlayerAdded:Connect(function(player) -- function runs when a player joins the game
	local enabled = false

	game.ReplicatedStorage["207"].OnServerEvent:Connect(function()
	    enabled = true
	    print(enabled)
	end)
	
	while wait(1) do
	    print("Check")
	    if enabled == true then
		if player.Character.Humanoid ~= nil then --checking if player character exists
	        	player.Character.Humanoid = player.Character.Humanoid - 1
		end
	    end
	end
end)

this script worked for me, comment or dm me on discord (erky?#2264) if you will have any problems

This discussion is preserved as it was. New answers, comments, and votes are closed.