How would you go about making a playtime reward system?

Hello!

I’m trying to make a playtime reward system where every 10 minutes, you get a reward. However, i can’t seem to find a tutorial on how anywhere. Can anyone explain how i would make one?

For Example:
10 mins after joining: 100 coins
20 mins after joining: 200 coins
30 mins after joining: 300 coins
1 hour after joining: 500 coins

Thanks!

2 Likes

Hi there! To achieve a playtime reward system, here’s an example of what you can do:

local Players = game:GetService("Players")

-- Define your rewards
local Rewards = {
	{
		Time = 600, -- 600s = 10 minute,
		Coins = 100
	},
	{
		Time = 1200, -- 1200s = 20 minute,
		Coins = 200
	}
}

-- Detect when the player joins the game
game.Players.PlayerAdded:Connect(function(player)
	
	-- Initialize their playtime. Note; I'm using seconds in this example, but feel free to use minutes.
	local playerPlaytime = 0
	
	
	-- Every one second
	while true and wait(1) do
		
		-- Add a second to their playtime
		playerPlaytime += 1
		
		-- Check if any reward was reached
		for i, v in ipairs(Rewards) do
			if v.Time == playerPlaytime then
				-- Do something with v.Coins
			end
		end
	end
	
end)
3 Likes

Wow, thank you so much! How would i add a claim button tho?

Also, is this a server script or local?

1 Like

That’s a server script. If you want to add a claim button, you could use RemoteEvents.

1 Like

This is just a basic system you could use for the countdown part of it, which would be run client-side.

You would have a server-side Script and a client-side LocalScript connected by a RemoteEvent.

When the player joins, the RemoteEvent is used to tell the client to begin the countdown. When the countdown has finished, the client will use the RemoteEvent to tell the server to add the rewards. Modify this how you want!

Client-side example:

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent") --change to your event
local countdown = 600 --change to your minutes countdown, in seconds
local exampleLabel = nil --change to a text label you want only the client to see and update

event.OnClientEvent:Connect(function()
    for i = countdown, 1, -1 do
        exampleLabel.Text = i
        task.wait(1)
    end
    event:FireServer()
end)

please note I haven’t implemented any step-up system into this, so it can just be used for the countdown. Hope this helps!

1 Like

Thanks! but if there are multiple rewards, this wouldn’t go with it

1 Like

What part would i put in the remote event?

The RemoteEvent would go in ReplicatedStorage, since both the client and server need to access it.

2 Likes

I mean like the script @maxencexz provided

yes, I am aware. RemoteEvents are used to communicate between the server and the client, so they would need to go in the best place that both of them can access.

1 Like

I Only have the option of OnServerEvent

You have to define your RemoveEvent anywhere in the script, if that’s what you were asking for. Here’s a tiny edited version:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage.PATH_TO_YOUR_REMOTE

-- Detect when the player joins the game
game.Players.PlayerAdded:Connect(function(player)
	
	-- Define your rewards, locally this time
	local Rewards = {
		{
			Name = "firstReward",
			Time = 600, -- 600s = 10 minute,
			Coins = 100,
			Reached = false,
			Claimed = false,
		},
		{
			ame = "secondReward",
			Time = 1200, -- 1200s = 20 minute,
			Coins = 200,
			Reached = false,
			Claimed = false,
		}
	}
	
	-- Detect when the remote is fired from a client
	RemoteEvent.OnServerEvent:Connect(function(remotePlayer, rewardName)
		if remotePlayer ~= player then return end
		for i, v in ipairs(Rewards) do
			if v.Name == rewardName and v.Reached then -- If the reward is found and it is reached
				if not v.Claimed then -- Check if it was claimed already
					-- Do something with v.Coins
				end
			end
		end
	end)
	
	-- Initialize their playtime. Note; I'm using seconds in this example, but feel free to use minutes.
	local playerPlaytime = 0
	
	-- Every one second
	while true and wait(1) do
		
		-- Add a second to their playtime
		playerPlaytime += 1
		
		-- Unlock rewards if playerPlaytime is enough
		for i, v in ipairs(Rewards) do
			if v.Time == playerPlaytime then
				v.Reached = true
				break
			end
		end
	end
	
end)

This is only the server script. You would have to make a local script so whenever the player clicks on a button, it fires the Remote. Example:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage.PATH_TO_YOUR_REMOTE

YOUR_BUTTON.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer("firstReward")
end)
5 Likes

Thank you so much! Remotes aren’t my strong suit :grimacing:

You’re welcome! Once you learn about it, you’ll see how simple they are to use. Feel free to send me a Direct Message on the DevForum or on Discord (maxencexz) if you need more help / have questions!

1 Like

LIFESAVER! Thank you sososos much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.