✓ Accepted answer
You can't have a LocalScript change the leaderstats value. You have to do it via remotes. For this I think it's going to be relatively easy but we need a few things:
- A RemoteEvent
- A localscript sending the remote event data
- A server-side script receiving the remote event data
First make a RemoteEvent in ReplicatedStorage and name it RacesWon. That's is going to enable communication between the server and the clients.
Next step we are going to make the server script receive the data and update the player's leaderstats:
local Remote = game.ReplicatedStorage.RacesWon
local function ServerEvent(player)
local RacesWonStat = player.leaderstats:WaitForChild("Races won")
RacesWonStat.Value = RacesWonStat.Value + 1
end
Remote.OnServerEvent:Connect(ServerEvent)
All that is saying is basically if the remote event got something from the client, the server code will execute. Think of it as phone calls and operators.
Next step we are going to make the client code which is easier. All you need to do is get a variable of your Remote Event and fire it whenever you want to:
local Remote = game.ReplicatedStorage.RacesWon
Remote:FireServer()
Your all done here are some links:
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model
2 comments
Thanks for helping and the added explanation, I knew it had something to do with this just didn't exactly know how to do it. Great explanation.
Thank you!