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)
What is the issue? Include screenshots / videos if possible!
I tried making it client sided but it just didn’t work
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried YT and Devforum.
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?
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
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:
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.
On the client, retrieve this value and set it to some variable (x)
Get the time left using x - workspace:GetServerTimeNow()
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.
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
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.