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

While loop isn't executing in my script for some reason?

When Hunger OR Thirst gets to 0 it should start to damage the player When they get to zero it does absolutely nothing.

local player = game:GetService("Players").LocalPlayer
dying = false

if player.Character ~= nil then
	player.Character:WaitForChild("Humanoid").Changed:Connect(function(prop)
		if prop == "Health" then
			player:WaitForChild("Health").Value = player.Character:WaitForChild("Humanoid").Health
		end
	end)
end

if player:WaitForChild("Hunger").Value == 0 or player:WaitForChild("Thirst").Value == 0 then
	dying = true
end

player.Character.Humanoid.Died:Connect(function()
	player:WaitForChild("Hunger").Value = 100
	player:WaitForChild("Thirst").Value = 100
end)


while dying do
	player.Character.Humanoid.Health = player.Character.Humanoid.Health - 15
	wait(1.5)
end

10 comments

0

Don't worry about the top part about health..

0

lmao "while dying do"

0

What's so funny about that? Lol

0

is this a local script located in the charcter or starterpack?

0

make sure it's a localscript and located in starterpack

0

then just make player = script.Parent

0

and remove all ".Character"

0

you also dont need the "if player.Character ~= nil then"

0

Why would I remove .Character? I need to access the character to access the humanoid object.

0

And if I were to replace the player with script.Parent it would be the character model. Which isn't what I need. I have these values stored in the player object, not the character.

1 answer

PROBLEM IS SOLVED - To anyone wondering something similar you just need to use it with a changed event.

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