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

Health is not a valid member of Model? (SOLVED)

Asked by
drew1017 330 Moderation Voter
8 years ago
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
    print 'charloaded'
end

game.Players.LocalPlayer.Character.Health:Destroy()

As you can probably see, im trying to delete the health regen script. However whenever this script runs:

14:16:36.233 - Health is not a valid member of Model

I have no idea how that could happen, as even if Health's parent is nil, I believe it wouldn't show a nonexistance error?

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

You should wait until Health is a member of the Character, using the WaitForChild function.

local player = game.Players.LocalPlayer

--wait until character exists
repeat wait() until payer.Character
local character = player.Character
print('char loaded')

--wait until health exists
local health = character:WaitForChild('Health')

health:Destroy()
0
i was using findfirstchild but it takes time to load... yes it works (i tested your script)... davness 376 — 8y
0
Ah, yes i haven't experimented with WaitForChild alot so my script setup around that is really primitive. Thanks! drew1017 330 — 8y
0
Accept my answer if it effectively answered your question(: Just so people will know it's already answered. Goulstem 8144 — 8y
Ad

Answer this question