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

"Health Is Not A Valid Member of Player"?

Asked by 7 years ago
Edited 7 years ago

Hi, total noob to RemoteEvents here. I'm making a weapon. When the handle of the weapon is touched by somebody other than the Player who is attacking, it takes damage to the victim. I have two values, attacking and debounce. The code is inside a local script inside the tool. The RemoteEvent is in ReplicatedStorage, and the script is inside ServerScriptService.

The clip of the local script containing the :FireServer() looks like this:

function onTouch(part)
    if attacking == true and debounce == true then
        if part.Parent.Name ~= player.Name then
            local vhum = part.Parent:findFirstChild("Humanoid")
            if vhum and vhum.Health > 0 then
                game.ReplicatedStorage.RemoteEvents.TakeHealthFromWeapon:FireServer(player, vhum, damage)
                attacking = false
            end
        end
    end
end

The script looks like this:

function onTHFW(vhum, damage)
    vhum.Health = vhum.Health - damage
end

game.ReplicatedStorage.RemoteEvents.TakeHealthFromWeapon.OnServerEvent:connect(onTHFW)

When the tool is activated, I get this error from the Script:

"21:41:29.298 - Health is not a valid member of Player" ... "21:49:55.547 - Script 'ServerScriptService.Script', Line 3"

Any help is appreciated. Thanks. :} ~Loughdough

0
Health is not a valid member of Player. Use Player.Character.Humanoid.Health instead. abnotaddable 920 — 7y

1 answer

Log in to vote
1
Answered by
movsb 242 Moderation Voter
7 years ago

Your problem is that on the server 'vhum' is the client (a fancy word for player) that is firing to the server.

When you fire parameters from the client to the server via a remote event, the first parameter on the server is the client that fired the data.

You are getting that error because Player.Health does not exist.

You should change your server code to this:

game.ReplicatedStorage.RemoteEvents.TakeHealthFromWeapon.OnServerEvent:connect
(function(Player, vhum, damage)
    vhum.Health = vhum.Health - damage;
end)

If you are confused still, lets say that player "Bob" hits player "Barney" with his sword; when Bob's client fires to the server, and you print(Player.Name), you would get the output Bob; and in your case if you also print(vhum.Name) then you would get Barney.

I hope this helped you out.

0
It's not getting any errors now, but now it's still not taking any damage.. I defined damage as "local damage = 30" at the beginning of the local script. Got any idea on how to fix this? :{ Loughdough 291 — 7y
0
I do, but it would take another entire answer to explain. It has to deal with how tools actually work in filtering enabled environments. I will edit my original answer to include some more information for you, but it may take a bit because i am usually very busy. movsb 242 — 7y
0
@laczka I'll just write another question. Feel free to answer it. Thanks for the help! Loughdough 291 — 7y
0
I have already gotten fairly far into the answer though :( movsb 242 — 7y
View all comments (2 more)
0
@laczka I think it gives you higher reputation if you have two accepted answers instead of one. Which is good! You can answer it here: https://scriptinghelpers.org/questions/44724/weapon-isnt-dealing-damage -- Thanks :} Loughdough 291 — 7y
0
Thanks, I will be sure to :) movsb 242 — 7y
Ad

Answer this question