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

[SOLVED] Remote Event cant access/change player's data properly. Help me, please?

Asked by 5 years ago
Edited 5 years ago

Hello! :) I made a system that when a player press a button on a ScreenGui, the value in leaderstats will change. It works perfectly, the values changes both in the client and in the server. But now I got a problem: I want to change the Local Player's Health to the new value in the leaderstats, so for this I've tried to add this on this simplified version of the Server Script, just for testing if it will work correctly:

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
    print(game.Workspace.player.Humanoid.MaxHealth.Value)
end

So when I run it and invoke the server, this appears on the output: player is not a valid member of Workspace

I've also tried change to

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
    print(game.Workspace[player].Humanoid.MaxHealth.Value)
end

And

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
    print(game.Workspace:FindFirstChild(player).Humanoid.MaxHealth.Value)
end

But they didn't worked too.

0
player.Character? Also, I either don't know roblox's humanoids or the ".Value" part of the print should be removed. unless it is a IntValue of some sort (which still should be named something like MaxHealth2) the8bitdude11 358 — 5y
0
'player' is a Player Instance. You can only index things in the Explorer by name, not object. Instead, use the player's Name. game.Workspace[player.Name].Humanoid.MaxHealth - remember that player's don't need a character to invoke things which would produce an error in your code. MaxHealth is a number so it has no attributes like 'Value'. pidgey 548 — 5y
0
Thank you! DanielGamerXD 9 — 5y
0
I've changed the 2 line to this: print(player.Character.Humanoid.MaxHealth) DanielGamerXD 9 — 5y

1 answer

Log in to vote
0
Answered by
vkax 85
5 years ago

Simple solution

You just simply have to reference the name, not the player. You're calling for the player itself, not for the name of it.

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
    print(game.Workspace:FindFirstChild(player.Name).Humanoid.MaxHealth.Value)
end
Ad

Answer this question