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

Health is not valid member of Model?

Yes, I know what you're thinking; "This is so easy, health is not a valid member of a model!".

But, I used the FindFirstChild() function, but still, it doesn't work.

Client script: (Local script, inside tool)

tool = script.Parent
player = game.Players.LocalPlayer


tool.Equipped:Connect(function(mouse)
	mouse.Icon = "http://www.roblox.com/asset/?id=2312592107"
	mouse.Button1Down:Connect(function()
	game.Workspace.KillExplosion.KillExplosionCreate:FireServer(mouse.Target, tool.Handle)
	
	
	end)
end)


Server script: (Normal script, inside workspace)

debounce = false

	script.KillExplosionCreate.OnServerEvent:Connect(function(player, target, tool)	
		if debounce == false and target.Parent:FindFirstChild("Humanoid") then
			debounce = true
			tool.BrickColor = BrickColor.new("Really red")
			player = target.Parent.Humanoid
			player.Health = player.Health - 18
			wait(1)
			debounce = false
			tool.BrickColor = BrickColor.new("Sea green")
			
	end
end)

I have no idea why this doesn't work. So, when I click on something that doesn't have a Humanoid I get the error:

Health is not valid member of Model

BUT I USED THE FIND FIRST CHILD FUNCTION! WHY??!!

ERROR AT LINE 8, SERVER SCRIPT

5 comments

0

I tested your script,it works fine, when you click on a model with a humanoid did its health decrease?

0

you might want to try changing line 07 to local player instead, as there is already another player argument defined at the start of the funcction

0

Humanoid.Health = Humanoid.Health - 19 ( or use the :TakeDamage() method which is easier, Humanoid:TakeDamage(19) )

0

The problem is, if I don't click on anything with a Humanoid, I get an error.

0

But FindFirstChild is supposed to remove that error, and ONLY run if the thing that is clicked is a Humanoid.

1 answer

Model does not contain a Health value. You're trying to change the .Health property of a Model. Health is a property of Humanoid. Try going down/up the Hierarchy and find the Humanoid of the Player.

If you get the error when clicking something without a humanoid, try using if [object]:FindFirstChild("Humanoid") then. It will only execute the remaining code in it's block if it can find a Humanoid. This should eliminate the error.

According to your error, Humanoid is the name of the Model. If :FindFirstChild() isn't working for you, try using object:IsA("Humanoid") then. If it's a model, it won't continue. But if the object is a Humanoid, the code will continue.

I don't quite understand what you're trying. Please contact me in Discord. I can further assist you there.

Bark#4260

1 comment

0

I added you, I am FKH 4

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