Need RemoteEvents Script Support

Basically, I am trying to add a certain amount of “candies” which is a currency, to a certain player’s leaderstats. How would I achieve this?

I appreciate any help, and thank you in advance.

--// Client Script \\--
local player = game.Players.LocalPlayer

replicatedStorage.UpdateValue:FireServer(player, "Candies", 10)

--// Server Script \\--
local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage.UpdateValue.OnServerEvent:Connect(function(player, valueName, amount)
    local playerName = game.Players:FindFirstChild(player.Name)
    if valueName == "Candies" then
    	game.Players[playerName].leaderstats.Candies.Value += 1
    end
    game.Players[playerName].leaderstats.Candies.Value += 2
end)

I get this error: ServerScriptService.Script:8: invalid argument #2 (string expected, got Instance)
I also feel like there are other errors in my script, any help is appreciated.

playerName is the Player Instance, not the actual name of the player.

replicatedStorage.UpdateValue.OnServerEvent:Connect(function(player, valueName, amount)
    if valueName == "Candies" then
    	player.leaderstats.Candies.Value += 1
    end
    player.leaderstats.Candies.Value += 2
end)

I fixed your script. You did game.Players:FindFirstChild(player.Name) and then game.Players[playerName] which is highly unnecessary as player is already the player, no need to get the player a million more times.

You can also remove player from replicatedStorage.UpdateValue:FireServer(player, "Candies", 10), as it automatically gets sent as the first argument.

Oh, alright!

I will test it out.

Thank you both for your responses! :smiley: