Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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.

0
It is way easier to do repeat (...) until HumanoidRootPart == nil. Just saying. DeceptiveCaster 3761 — 5y
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? Louix27626 83 — 5y
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 Louix27626 83 — 5y
0
You can stick everything that your script does in that repeat loop. DeceptiveCaster 3761 — 5y
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! Louix27626 83 — 5y
Ad

Answer this question