How can i make this daily reward system client sided?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make this script client sided, because right now its on the server side. Here’s my code :
local dataStoreService = game:GetService("DataStoreService")
local timeDataStore = dataStoreService:GetDataStore("timeDataStore")
local waitTimeHours = 24
local db = false
local claimed = false
local goalTime = nil

game.Players.PlayerAdded:Connect(function(player)
	if timeDataStore:GetAsync(player.UserId.."-Daily") then
		goalTime = timeDataStore:GetAsync(player.UserId.."-Daily")
		claimed = true
	end
	spawn(function(timer)
		while true do
			wait(1)
			local difference
			if claimed == true then
				if goalTime ~= nil then
					if os.time() < goalTime then
						difference = goalTime - os.time()
						local hours = math.floor(difference/3600)
						local minutes = math.floor((difference - (hours*3600))/60)
						local seconds = ((difference - (hours * 3600)) - (minutes * 60))
						if hours < 10 then
							hours = 0 .. hours
						end
						if minutes < 10 then
							minutes = 0 .. minutes
						end
						if seconds < 10 then
							seconds = 0 .. seconds
						end
						script.Parent.Parent.Treasure.Timer.TextLabel.Text = (hours..":"..minutes..":"..seconds)
					else
						claimed = false
						goalTime = nil
						timeDataStore:RemoveAsync(player.UserId.."-Daily")
						script.Parent.Parent.Treasure.Timer.TextLabel.Text = ("Chest Ready!")
					end
				end
			end
		end
	end)
end)

script.Parent.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:FindFirstChild(touched.Parent.Name)
		if db == false then
			db = true
			if timeDataStore:GetAsync(player.UserId.."-Daily") == nil then
				timeDataStore:SetAsync(player.UserId.."-Daily", (os.time() + waitTimeHours * 3600))
				goalTime = timeDataStore:GetAsync(player.UserId.."-Daily")
				claimed = true
			end
			wait(5)
			db = false
		end
	end
end)
  1. What is the issue? Include screenshots / videos if possible!
    I tried making it client sided but it just didn’t work

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum.

3 Likes

Exactly what you’re looking to do. By AlvinBlox even. Can’t go wrong.

1 Like

His video sorta helped, but my script is a chest not a gui and his script doesn’t display the amount of time left

1 Like

That’s unfortunate, however it shouldn’t be hard to convert that the core is there.
“I want to make this script client sided, because right now its on the server side”
So you’re looking to make a secure system into an unsecure system that can be hacked?

1 Like

You can’t convert all of this to the client. The server needs to have a say in saving and getting your data, and rewarding you with items.

All you can have the client do here is make UI changes. Using a RemoteEvent will let you tell the client to set UI and say what you got.

2 Likes

firstly, im using a chest and not a ui and also, i know some things need to be on the client, i know a few, but when i switch it to the client it still doesnt work

1 Like

This is indeed UI. It’s usually frowned upon to change any UI that only a specific player can see. It’d be beneficial to switch it to the client. This is how I’d do it:


  1. Set an attribute of the player on the server. This will hold workspace:GetServerTimeNow() + difference. The value represents the time in which you will recieve your daily reward, relative to the server time.
  2. On the client, retrieve this value and set it to some variable (x)
  3. Get the time left using x - workspace:GetServerTimeNow()
  4. Set the UI on the client using this new information

workspace:GetServerTimeNow() returns what os.time() and tick() return, but both the client and server recieve the same value. The timezone of the server and client may be different, causing issues with syncing using the two other functions.

1 Like

could, you turn my server script into how you explained it and also make a client side script

I’m not ChatGPT, I explained it so you could try on your own first!

1 Like

I might’ve fixed it my own way, but i think it wont work since the claimed variable inside of the server script will be set to claimed if one player touches the pad and if someone else tries to claim it then it wont work

Idk how to fix that bit, could you help with that bit

Making this client-sided is a terrible idea, because an exploiter is able to control everything, like getting to daily reward one thousand, or make the reward extremely high.

Almost everything must be controlled by the server, and only try to use RemoteEvents for Server > Client only.

Ok, i asked chatGPT for some code and it seems like it’ll work, so I’ll try it sometime