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

[ANSWERED] How to constantly check if HumanoidRootPart is deleted?

There is my script :

repeat wait() until player.Character

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Height = Instance.new("IntValue")
	Height.Name = "Height"
	Height.Parent = leaderstats

	while true do wait()

		local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
		repeat wait() until HumanoidRootPart
		Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8)

	end

end

My problem is when a player fall in the void, the HumanoidRootPart is deleted and it create an error, I wanted the script to constantly check if HumanoidRootPart is existing but i don't know how!

The script is in ServerScriptService and it's a normal one.

Thank you in advance ^^

1 answer

✓ Accepted answer

Okay, so you'll need to loop through the players and get their characters.

while true do
    for i, player in pairs(game.Players:GetPlayers()) do -- Loops through the players
	    local char = player.Character -- Character variable
	    if char:FindFirstChild("HumanoidRootPart") then -- Check for HRP
		    -- HumanoidRootPart found
		else
			-- HumanoidRootPart not found
		end
	end
	wait()
end

Insert the code you want in the HumanoidRootPart not found part.

5 comments

0

It is way easier to do repeat (...) until HumanoidRootPart == nil. Just saying.

0

Thank you for your answer but I didn't understand what i need to do :S do i need to paste this into my script before everything else or just in my while true loop?

0

But @MCAndRobloxUnited when doing this it will only continue the script if the HumanoidRootPart is nil isn't it? I want exactly the opposite

0

You can stick everything that your script does in that repeat loop.

0

Ok I'm just dumb xD Thank you very much @despicablejack2005 I needed 42minutes to figure out what to do haha forgive my bad scripting level!

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