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

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

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.

4 comments

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)

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

0

Thank you!

0

I've changed the 2 line to this: print(player.Character.Humanoid.MaxHealth)

1 answer

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

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