英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论