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 5 years ago
1local player = game.Players.LocalPlayer
2 
3 
4if game.Workspace[player.Name].Humanoid.Health == 0 then
5    script.Parent.Visible = false
6end

Error - Humanoid is not valid member of model

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 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:

1local plr = game.Players.LocalPlayer --assigning the player to the variable 'plr'
2local 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
3local hum = char:WaitForChild("Humanoid") --It will wait for the humanoid to be loaded, and assign it to the variable 'hum'
4 
5hum.Died:Connect(function() --When the humanoid dies, run this function:
6    script.Parent.Visible = false
7end)
0
Oh thank you trickortreat333444 -6 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 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.

1local player = game.Players.LocalPlayer
2local Character = player.Character or player.CharacterAdded:wait()
3 
4 
5if Character and (Character.Humanoid.Health == 0) then
6    script.Parent.Visible = false
7end

Answer this question