如何创建一个变量,可以在重新加入Roblox游戏后跟踪总共花费的时间?

huangapple go评论66阅读模式
英文:

How can I create a variable that tracks the total time spent in a Roblox game even after rejoining?

问题

如何创建一个变量,用来记录你在游戏中停留的时间,并且每次重新加入游戏时都会叠加。

所涉及的游戏是一个Roblox游戏。我还计划让脚本在你在游戏中停留特定时间后赠送Roblox徽章。

我创建了一个变量并使用了重复函数,但仅限于此。

英文:

how to make a variable that tells the amount of time you stayed in a game, and is stacked everytime you rejoin

the game in question is a roblox game btw. i also plan to make it so that the script gives you those roblox badges if you are in the game for a specific amount of time

i made a variable and used the repeat function, but thats it

答案1

得分: 1

我认为使用 'os' 模块来计算时间(执行时间)是一个不错的选择。

function updateTime()
    local currentTime = os.time()
    timePlayed = timePlayed + (currentTime - startTime)
    startTime = currentTime
end

这个函数计算并更新游戏时间。此外,你可以使用(自己创建)比较函数来发放徽章。

英文:

I think it's good to use 'os' module to calculate time(executing time).

function updateTime()
    local currentTime = os.time()
    timePlayed = timePlayed + (currentTime - startTime)
    startTime = currentTime
end

This function calculates and updates play time. Further, you can use(make yourself) compare function to give badges.

答案2

得分: 1

Roblox有一个存储数据的系统,即使玩家离开游戏,数据仍然可以保留。我将在这里提供文档链接:
https://create.roblox.com/docs/cloud-services/datastores

英文:

It looks like you need datastores. Roblox has a system to store data even after player leaves the game. I'll link the doc here just incase:
https://create.roblox.com/docs/cloud-services/datastores

huangapple
  • 本文由 发表于 2023年5月28日 16:51:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定