Amenities! So everyone, I have a question. Myself and friends own a cafe together, and we’re trying to create a database that stores our staffs minutes when they join the cafe, until they leave. For example, it would say “(user) has joined the cafe. data saved.” and, “(user) has left the cafe. (number) minutes were saved. We have an idea of what to do, however we were hoping someone could point us int he direction of how to set up the database.
You would use either tick()
or os.time()
on both join and leave, and add the difference to a datastore using UpdateAsync.
You could do what @posatta said if you want to keep it simple and in-game, but if you want to connect it with a Discord bot or something to see like a leaderboard or individual activity, it is a lot more complicated.
You would need to be an advanced programmer or have someone who is an advanced programmer in node.js in Lua and Node.js first. Personally, I find MongoDB a lot easier to use than MySQL for these purposes.
The way that I do it has a script in-game that as posatta said uses os.time() and calculates the difference, and then uses HttpService to add the activity to a database.
For when the PlayerRemoving event fires, you could set up some sort of Node express server that your script can post the activity to. This would probably require you to pay for some sort of hosting service.
It takes a lot of work to set up an activity system that’s integrated with Discord bots, but in the end, it is in my opinion a lot easier to view activity leaderboards and such.
I’d suggest doing what posatta and SS4PPHIRE said, but for the database itself, I’d suggest using something like SQLite or MySQL. This then links to the game with HttpService.
Yeah. The database service that you use really just depends on your skill level and what you’re utilizing it for.
To add onto what he said:
Use the PlayerAdded event and use a global table variable to store the players’ join times. For example:
_G.JoinTimes = {}
game.Players.PlayerAdded:connect(function(Player)
_G.JoinTimes[Player.UserId] = tick()
end)
game.Players.PlayerRemoving:connect(function(Player)
local JoinTime = _G.JoinTimes[Player.UserId]
DataStore:UpdateAsync(Player.UserId,function(Minutes)
Minutes = Minutes or 0
return Minutes + math.floor((tick() - JoinTime) / 60)
end)
_G.JoinTimes[Player.UserId] = nil
end)
I trust you can set up the data store scripting. Just use this as a sort of layout for how I would write such a script.
EDIT: If you choose this route, mark @posatta as the solution post.
Hope this helps. Thanks for reading and have a good day.
- Galactiq