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

Health is not valid member of Model?

Asked by
Oficcer_F 207 Moderation Voter
5 years ago
Edited 5 years ago

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

0
I tested your script,it works fine, when you click on a model with a humanoid did its health decrease? aazkao 787 — 5y
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 aazkao 787 — 5y
0
Humanoid.Health = Humanoid.Health - 19 ( or use the :TakeDamage() method which is easier, Humanoid:TakeDamage(19) ) EpicMetatableMoment 1444 — 5y
0
The problem is, if I don't click on anything with a Humanoid, I get an error. Oficcer_F 207 — 5y
0
But FindFirstChild is supposed to remove that error, and ONLY run if the thing that is clicked is a Humanoid. Oficcer_F 207 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
I added you, I am FKH 4 Oficcer_F 207 — 5y
Ad

Answer this question