I want to record time spent in a roblox game and then convert a certain amount of time spent in game into a certain amount of points which then get saved to a datastore and then also potentially to put the time spent in game or the points into discord through a webhook.
I have a small problem in the fact that I don’t know how to script, don’t know how to do a datastore, don’t know how to record time spent in game and convert it into points (or just record it) and I don’t know how to make a discord webhook that records that.
I would appreciate any help from any of you. Thank you in advance.
To track the amount of seconds they’ve played for, insert a value called seconds into the player when they join the game as follows:
game.Players.PlayerAdded:Connect(function(Player)
local seconds = Instance.new("IntValue")
seconds.Name = "Seconds"
seconds.Parent = Player
end)
Then add a while wait(1) do loop do add a second to the value every second as follows:
game.Players.PlayerAdded:Connect(function(Player)
local seconds = Instance.new("IntValue")
seconds.Name = "Seconds"
seconds.Parent = Player
while wait(1) do
seconds.Value = seconds.Value + 1
end
end)
The technique for this would be exactly like @Fondatix said in terms of using HTTP Service (discord has a webhook you can use to send data to it). There are already guides on the DevForum for things such as Discord Integration for ROBLOX so I recommend checking those out.
In your instance particularly though do what Fondatix said to track the time they have spent in game by creating a value which changes for them every second. Then what you want to do is detect
when they leave the game using the PlayerRemoving event. Inside the PlayerRemoving function you’d want to send their username as well as the time spent in game through the discord webhook so it can be displayed in a channel.