How would I make a claim button?

Hey! I’ve already got a working daily reward system but I want to connect this to a GUI, so when I click the claim button I receive the reward (PandaCoins). How would I script the GUI to appear only every 24 hours and the claim button to give the player the coins once they clicked it?

1 Like

Use a datastore (or any database service of your preference) and add a timestamp whenever they claim whatever it is they are claiming. Then whenever they attempt to claim an item, compare the current timestamp to the last claimed timestamp and then just check if 24 hours has elapsed.

2 Likes

thanks! I’m going to search for visual scripts because I’m new to scripting and don’t understand how to put together the parts you said.

To put what Jody is saying into script, as I know some people learn better off of examples:

-- user claimed reward, save current time to database
saveClaimTime(player, os.time())


-- user has connected, checking if they are able to get a reward 
local lastClaimTime = getClaimTime(player)
if (os.time() - lastClaimTime) >= 60 * 60 * 24 then -- difference in seconds of current time and last claim time - check if it's been greater than or equal to 24 hours (in seconds)
	-- it's been more than 24 hours since their last claim
end

Obviously I’m not going to write the whole thing - but this should give you a concept of what the code will look like.

1 Like

Use datastore and write timespan into it because when the gui is showing every 24 hours i can just sploit remote event so it must be delayed on server

What would I define getclaimtime as?

In words I’m thinking

local getClaimTime = when image_button is clicked

I get time when buton is presed +1d and when I will claim it the time must be >= to the saved one otherwise it will cancel claiming gift

saveClaimTime(player, os.time()) **( I don’t understand what this is for)

local lastClaimTime = getClaimTime(player)
local getClaimTime = when image_button is clicked+1d (Can someone translate this to code?)


local userdata
pcall(function()
	userdata=datastore:GetAsync(p.UserId)
end)
if userdata then

if (os.time() - lastClaimTime) >= 60 * 60 * 24 then
userdata={PandaCoins=userdata.PandaCoins+reward; rewardTime=os.time();}
datastore:SetAsync(p.UserId,userdata)
end
PandaCoins.Value=userdata.PandaCoins
else

	--[[
		Table format:
		PandaCoins=0;
		rewardTime=24029403294
	--]]	
	datastore:SetAsync(p.UserId,{
		PandaCoins=0;
		rewardTime=os.time();
	})

end

@shayner32 @mistr88

1 Like

It it +1day not second. …