Hi, I need help with a free gift system I am doing.
My system is a GUI that has different buttons with timers (I will show it below) and at the end of that timer the player can claim the gift and get money. The problem is that I don’t know how to make a datastore to avoid that the player after claiming the gift can leave the game and when joining again he can claim again the gift. I was also looking for the DataStore to be renewed every 24 hours, I mean, that when 24 hours pass since the player claims the gift he can claim it again (something similar to a daily gift system) but I don’t know how to do it in a UI.
UI:
UI for the timers and claim
- Local Script on the UI:
local mainFrame = script.Parent.Parent.Frame:WaitForChild("MainBG")
local giftsFrame = mainFrame:WaitForChild("GiftsFrame")
local openSoundSFX = script.Parent.Parent:WaitForChild("OpenFreeGiftSFX")
local claimEvent = game.ReplicatedStorage.ClientEvents:WaitForChild("MoneyEvents").FreeGiftClaim
local gift = giftsFrame:WaitForChild("Gift1")
local giftNotificationIcon = script.Parent.Parent:WaitForChild("TriggerOpen").GiftNotification
local minutes = 5 -- 5
local seconds = 0
local alreadyClaimed = gift:WaitForChild("Claimed")
alreadyClaimed.Value = false
-- Timers
--- Main function
repeat
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
if seconds < 10 then
gift.Timer.Text = tostring(minutes)..":0"..tostring(seconds)
else
gift.Timer.Text = tostring(minutes)..":"..tostring(seconds)
end
wait(1)
until minutes <= 0 and seconds <= 0 wait(0.2) giftNotificationIcon.Visible = true
gift.MouseButton1Click:Connect(function()
if minutes <= 0 and seconds <= 0 then
if alreadyClaimed.Value == false then
alreadyClaimed.Value = true
openSoundSFX:Play()
local reward = 20 -- change
claimEvent:FireServer(reward)
gift.ClaimedText.Visible = true
giftNotificationIcon.Visible = false
end
end
end)
Hope I can get some help. Greetings.