Adding Leaderstat after TextButton Click

I’m trying to create a gift system in my game. Everytime the gift pops up on their screen, I want them to be able to claim the gift and get a certain amount of currency. My issue is that it gives the player the currency but it does not stay. If they get even more currency added to their current currency, the currency that was claimed disappears. Any help would be great! Here’s my code:

local frame = script.Parent.Parent.RandomFrame3
local Player = script.Parent.Parent.Parent.Parent.Parent
local Stats = Player:WaitForChild("leaderstats") 
local ClaimText = script.Parent.Amount
local Clicks = Stats:FindFirstChild("Clicks")
local Rebirths = Stats:FindFirstChild("Rebirths")
local Short = require(game.ReplicatedStorage:WaitForChild("Short"))
local ClaimButton = script.Parent.ClaimFrame.Claim

local pets = Player.Pets
local mult = 4
for i,v in pairs(pets:GetChildren())do
	if v.Equipped.Value == true then
		mult = mult + v.Equipped.Parent.Multiplier2.Value
	end	
	end

if Clicks.Value >= Rebirths.Value then
	local Total = Clicks.Value * mult
	ClaimText.Text = "+"..Short.en(Total).." Clicks"
end
ClaimButton.MouseButton1Click:Connect(function() 
	local Total = Clicks.Value * mult
	if Clicks.Value >= Rebirths.Value then
		game.Players.LocalPlayer.leaderstats.Clicks.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value + Total
		script.Parent.Parent.Visible = false
	end
end)

Just to clarify, the code works perfectly fine, its just the currency does not stay when the button is clicked.

What do you mean by “stay”
(char limit)

Are you updating the actual value in the leaderstats? I can’t find that line.

That’s because you’re performing the change on the client and not on the server.

1 Like

I agree with this
(char limit)

No, don’t do that.

Use a remote to communicate the server and give the player his stats from the server

Oh yeah dont use that line, like @Valkyrop said use a remote event

How do I fix that? I looked up lots of things but yet nothing.

Some people told me not to use Remote’s because people could create autofarm scripts/exploits in general.

Use a RemoteEevent to create the folder.

Add an Anti exploit in that case, and add a special parameter to prevent the server from picking up those requests.

use remotes as it allows the client to communicate with the server. This should help: Remote Functions and Events

RemoteEvents are your only option. It’s really the only way for a client to communicate with the server. Exploits can take advantage of these, yes, but you can be smart with how you use them to make it harder for people to exploit your scripts.