#fixing a script

1 messages · Page 1 of 1 (latest)

rugged edge
#

i got a script from someone else, which keeps track of how long the player has been offline for. can this be changed to not be manupilatable by the player? (script below)

red sierra
#

wym manupilatable 💔

#

@rugged edge

rugged edge
#

so people can change the time for it

#

by changing their devise clock

red sierra
#

yo @rugged edge

#

i fixed it

#

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")

local datastores = {}

local function getUTCTime()
local success, response = pcall(function()
return HttpService:GetAsync("http://worldtimeapi.org/api/timezone/Etc/UTC")
end)

if success then
    local data = HttpService:JSONDecode(response)
    return data.unixtime
else
    return os.time()
end

end

Players.PlayerAdded:Connect(function(player)
local userData = DataStoreService:GetDataStore("UserData", player.UserId)
datastores[player.UserId] = userData

local timePlayerLeft = userData:GetAsync("timeLeft") or getUTCTime()
timePassed = getUTCTime() - timePlayerLeft

end)

Players.PlayerRemoving:Connect(function(player)
if not datastores[player.UserId] then
return
end

local timePlayerLeft = getUTCTime()

datastores[player.UserId]:SetAsync("timeLeft", timePlayerLeft)
datastores[player.UserId] = nil

end)

#

if that dont work ask chatgpt

#

or use visual studio code

rugged edge
#

hmm

red sierra
#

for debugging

rugged edge
#

should still work the same right?

red sierra
#

yes

rugged edge
#

alr

#

ill try replacing the script with it later

red sierra
#

okay

#

btw u have to enable http services @rugged edge

#

the script gets their time from a website using that

rugged edge
#

alr

rugged edge
#

link takes me to a website that looks completley disfunctional

#

im just going to ask someone else

dense heart
# rugged edge

your script is already not manupilatable by the player. all you have to do is literally nothing. maybe add game:bindtoclose so it saves properly at all times

rugged edge
dense heart
#

datastores dont run on client

rugged edge
#

does bro not know how os.time() workscrying

dense heart
#

datastores run on server

rugged edge
#

this isnt datastores

dense heart
#

clients can change their os clock all they like, this isn't going to change the server's clock

rugged edge
#

wha

#

the script USES the clients os clock

dense heart
#

it does not

#

when you call os.time on the server, it returns the server time

rugged edge
#

can you do a quick favour for me

#

go to the documentation

#

and search up os.time()

dense heart
#

the only maybe exception to this is if you're doing this in studio, which is roblox's half-baked attempt at running servers on your client pc. that's not going to be possible in live servers

rugged edge
#

it will say that the player can manipulate it...

dense heart
rugged edge
#

let me send you a screenshot of the documentation

#

literally reads "However, users can easily disable sync behavor and set the system time to anything they want"

dense heart
#

i can see how you're confused by that

#

that is talking about using os.time on the client

#

the client can desync themselves from the server's os.time

rugged edge
#

ah

dense heart
#

that is not going to come up here because datastores only run on the server

rugged edge
#

so i will be able to manipulate it in studio but not in actual experience?

dense heart
#

that's a maybe in studio, i haven't tested it but it seems reasonable because studio tends to run the server side locally. but yeah no in an actual experience, all roblox servers have synchronized os.time meaning they all return the same value. clients cannot mess with that.

rugged edge
#

ah

#

are you CERTAIN of this though

dense heart
#

yes i am 100% certain of this.

rugged edge
#

because if you arent then players can just completley cheat it

#

but alright i trust you

#

since you have high roles ig

dense heart
#

not 100% on the studio side, but regular players aren't going to be opening your game in studio

#

if they could, you'd have way bigger problems ;p

rugged edge
#

i was able to maniuplate it in studio

#

but alright then

dense heart
#

yeah, you can 100% definitely trust os.time in the actual experience / roblox player, like for regular players joining your game, no issues there. clients cannot tamper with the server's os.time