How to make leader stats update separately

Hey,So I made a leaderstat and made a remote event fire on all servers when clicked(This script is in Starter Gui) And made it so that when its received it would change the leaderstat, however it changes it for all players,how do I fix this?

1 Like

Provide us your current code. We need a code to fix…

1 Like

This code to send the remote event:
game.ReplicatedStorage.HEADINCREASESTAT:FireServer()

The code to receive:
game.ReplicatedStorage.HEADINCREASESTAT.OnServerEvent:Connect(function()
Value.Value = Value.Value + 1
end)

You should try using the player parameter of OnServerEvent (Which is the player that made the remote event fire, in this case it would be the player who clicked)

game.ReplicatedStorage.HEADINCREASESTAT.OnServerEvent:Connect(function(player)
    player.leaderstats.STATNAME.Value = player.leaderstats.STATNAME.Value  + 1
end)

Should work.

To add to this, this is extremely insecure. Someone could access your code and fire this remote over and over millions of times to inflate the value. If you’re planning on using this is something that will be used by people, seriously look into securing remotes. There is a tutorial on the API page for that.

Doesnt seem to work (30 CHARACTERS)

Okay,I’ll look into that. (30 CHAR)

Hey,I tried that and it didnt seem to work

Where did you put the OnServerEvent and the FireServer?

(Tell the type of scripts you placed them, local script or server script)

For the firing its in a local and onserver is just script

Did you replace STATNAME with the stat name? The code they gave should work.

Part of the issue is we need to understand what this is being used for.

(If I also may ask what is this ā€œ30 charā€ you keep repeating).

If you can handle the click on the server, just do that.
On top of what everyone else is saying, the code provided should work. Its dependent on what you did to try to implement it now.

Yep I did that (30 CHARACTERS)

Am just trying to make a value in the leader stat change when a player clicks in a script inside the starter GUI,and am saying 30char as the forums requires a minimum of 30 character to reply to someone.

Could you show the full script?

Please don’t try to bypass the 30 character minimum. It is there for a good reason. Ideally your responses will be filled with something that can help us diagnose your problem. Scripts don’t usually just ā€œnot workā€. Providing some type of error logs would be extremely helpful to everyone here, as well as showing the full script.

--ServerSide
game.Players.PlayerAdded:Connect(function(plr)
local StatName = Instance.new('IntValue')
StatName.Name = 'Stat'
StatName.Value = math.random(10, 100)
StatName.Parent = plr
end)
local event = game.ReplicatedStorage:WaitForChild('Change')
event.OnServerEvent:Connect(function(plr, amount)
plr.leaderstats.Stat.Value = plr.leaderstats.Stat.Value + amount
end)
--ClientSide
while wait(10) do
game.ReplicatedStorage:WaitForChild('Change'):FireServer(math.random(10, 25)
end

This should work, change the client sided code for your own condition, yet i recommend learning the basics of roblox scripting, as you may want to do more complex things.
Make sure you make a remote event inside replicated storage named ā€˜Changed’

Sorry I’ll try not to bypass it, The code works now because am stupid and forgot I added a capacity system and the capacity was full so nothing would happen when you click.