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

How do you access leaderboard from a different script?

Asked by 5 years ago

I already have a savable leaderboard. Its all good.

Now, I am making a daily reward system. It is working, but it won't reward the player.

Cash is not working.

This is the cash part of my leaderboard

local cash = Instance.new("IntValue",stats)
    cash.Name = "Cash" 

This is the daily reward script

local reward = possibleRewads[math.random(1,#possibleRewads)]
game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
            local connection
            connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
                if triggeringPlayer == player then
                    print("Reward Claimed")
                    player.leaderstats.cash.Value = player.leaderstats.cash.Value + reward
                    DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
                    connection:Disconnect()
                end
            end)
0
How is player (not triggeringPlayer since that's given in the Remote) defined in the second script? xPolarium 1388 — 5y
0
Thats it. its triggeringPlayer == player Asher0606 36 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You wrote player.leaderstats.cash.Value but you named it Cash. If you inspect the output (F9), it should say something about that in the server output.

Also note that you need to disconnect the connection if the player leaves the game (in case they never claim the reward).

0
Thank you! I didn't realize that. lol Asher0606 36 — 5y
Ad

Answer this question