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

My script isn't working I also have the error. Any fixes?

Asked by 4 years ago


local player = game.Players.LocalPlayer if game.Workspace[player.Name].Humanoid.Health == 0 then script.Parent.Visible = false end

Error - Humanoid is not valid member of model

2 answers

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

The script instantly runs as soon as the script is loaded, and the character and humanoid takes a bit longer to load, therefore the character and humanoid won't exist by the time the script runs.

Also, I'm guessing you're trying to detect when the player dies, so just use humanoid.Died instead of Humanoid.Health.

Example:

local plr = game.Players.LocalPlayer --assigning the player to the variable 'plr'
local char = plr.Character or plr.CharacterAdded:Wait() --assigning the character to the variable 'char', and if doesn't exist by the time the script runs it'll run the 'or' statement, aka wait for the character to be added
local hum = char:WaitForChild("Humanoid") --It will wait for the humanoid to be loaded, and assign it to the variable 'hum'

hum.Died:Connect(function() --When the humanoid dies, run this function:
    script.Parent.Visible = false
end)
0
Oh thank you trickortreat333444 -6 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

What you could do is: as the script runs as soon as it is loaded which means the the humanoid might not have a chance to be loaded yet.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()


if Character and (Character.Humanoid.Health == 0) then
    script.Parent.Visible = false
end

Answer this question