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
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.