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

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

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

✓ Accepted answer

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()

3 comments

0

i was using findfirstchild but it takes time to load... yes it works (i tested your script)...

0

Ah, yes i haven't experimented with WaitForChild alot so my script setup around that is really primitive. Thanks!

0

Accept my answer if it effectively answered your question(: Just so people will know it's already answered.

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