How to Add points to leaderboard with Remote Event

I have made a remote event when it gets triggered I want a particular value to be added to the player’s leaderboard. I ain’t sure how do I do this.

Heres What I have.

game.ReplicatedStorage.Coin.OnServerEvent:Connect(function(player)
print(“Awaiting for coins!”)

end)

4 Likes

player.leaderstats.Coin.Value = player.leaderstats.Coin.Value + 1

Hope this helps.

2 Likes

In server script service

    game:GetService("ReplicatedStorage").Coin.OnServerEvent:Connect(function(player)
          
   --[[ local player = Players.LocalPlayer


    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
   --assuming you already created a leaderboard , with currency Coins ]]
   
    end)
3 Likes

I ain’t sure why but it doesn’t seem to work. The event fires properly but the value isn’t added to the player’s leaderboard. (no errors in the output)

1 Like

Do you have a local script firing the sever first?

Yeah I do have a local script which fires the server first.

Can I see that script?
–thirty chars

it works, you need to create a leaderboard first and insert an int value called Coins to the player, the leaderboard folder should be named leaderstats
edit: show us your scripts and where they are placed,

I already have a leaderboard with int value called Coin.

If that script works and you no longer need help please mark it as the solution.

Here

local character = script.Parent 
 
local player = game.Players.LocalPlayer

local humanoid = character:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
    if humanoid.Jump == true then
        print(player.Name.." just started jumping!")
        
        local value = math.random(1,10)

        if value == 10 then
            print(player.Name.." got lucky, and won some coins!")

     game.ReplicatedStorage.JumpCoin:FireServer()

            -- Insert a remoteevent or a module function here for coins
        end
    else
        print(player.Name.." just ended their jump.")
    end
end)

It Basically should fire when the player jumps but a bit random.

1 Like

Ok then yes with script @XxELECTROFUSIONxX it will work.

1 Like

Trying to figure it out, i’ll recheck everything.

Would you be able to show the Script which creates the leaderstats?

game.Players.PlayerAdded:connect(function(plr)
	local stats = Instance.new("BoolValue",plr)
	stats.Name = "leaderstats"
	
	local cash = Instance.new("IntValue",stats)
	cash.Name = "Coins"
	cash.Value = 0
end)
2 Likes

I’m quite sure leaderstats should be a folder.

2 Likes

You used two end)s when only one was needed.

@ZvClaw if you copied this exactly, remove one end)

2 Likes

It worked! I didn’t name the remote event properly in the script my bad.
Thanks for helping out everyone!

2 Likes

I’m late, but why are you trusting client, run the random on the server.

2 Likes

Just a note because I didn’t (unless I missed it) see someone say it, you should never trust the client with anything. If you need to determine when to give the player coins, you should do the calculations on the server rather than on the client as the client can easily be exploited.