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)
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.