I have a script in ServerScriptService than takes in a player and value. The script is below. I want to make it so it increases a players leaderstat by the value. My output in below, any help?
Script:
local event = game.ReplicatedStorage.PlayerClicked
event.OnServerEvent:Connect(function(player, value)
print(player)
print(value)
game.Players[player].leaderstats.Clicks.Value = game.Players[player].leaderstats.Clicks.Value + value
end)
You already have a reference to your player from the event handler, so you don’t need to access it through Players. Also, because your object reference is a player object and not their name, that’s what you’re getting the error for.
Just replace game.Players[player] with player and you should be good.
The error comes from the fact that you are inserting the player in the brackets rather than their name. It would work if you did player.Name, but that would be redundant since you already have player.
So just do this instead.
player.leaderstats.Clicks.Value = playerleaderstats.Clicks.Value + value