Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does tick() return the player?

Asked by 1 year ago
Edited 1 year ago

im making a ping displayer thingy and for some reason i enter tick and it returns the player

localscript (yes it is inside of startergui)

while true do
    local ping = game:GetService("ReplicatedStorage").Remotes.getPing:InvokeServer(tick())
    script.Parent.Text = tostring(ping)
    task.wait(0.1)
end

Serverscript:

game:GetService("ReplicatedStorage").Remotes.getPing.OnServerInvoke = function(old)
    print(old)
end

it prints my roblox name, why?

Also the problem seems to be serversided because i printed tick on the client and it worked

2 answers

Log in to vote
2
Answered by
blowup999 659 Moderation Voter
1 year ago

do function(plr, old)

Because the client is sending data to the server, for security reasons, roblox lets you know which player is sending the data everytime it's invoked and it's an automatic parameter given to the server. Therefore, the parameters you pass will be the second, third, etc. values passed to the function.

Ad
Log in to vote
1
Answered by 1 year ago

You probably shouldn't use tick(), Roblox has provided superior features such as DateTime.now().UnixTimestamp. Anyways, Roblox by default sends the Player instance and whatever else you decided to send over the remote. You can ignore the Player instance with the following:

game:GetService("ReplicatedStorage").Remotes.getPing.OnServerInvoke = function(_, old)
    print(old)
end
1
you can use os.time() and workspace:GetServerTimeNow() T3_MasterGamer 2189 — 1y

Answer this question