Ah alright, I have written some steps down you would have to follow for this.
Instructions
Getting Track Of the Player’s Time
I would create a new script into ServerScriptService. Inside of this script you first of all check if a player has joined the game. Like this.
game.Players.PlayerAdded:Connect(function(player)
end)
Now you can create a new value that gets a hold of the player’s time. You would most likely want to create an intvalue for this.
local timeInGame = Instance.new("IntValue")
timeInGame.Name = "TimeInGame"
timeInGame.Parent = player
If you would also like to make other players see this you could insert it into the leaderstats instead of the player.
Now we can create a new loop that adds a point every second to the player’s time. We would do that like this:
while wait(1) do
timeInGame.Value += 1
end
Awesome! Now we have the script that gets track of the player’s time. However, you may want to save this. I will not explain the entire script, as a great way to learn is by discovering yourself, however, I will leave a link to the documentation of DataStoreService what you will need for this. If that doesn’t help you, then there are plenty of great tutorials on YouTube about it.
Here’s a link to a DevHub post that goes more in-depth about DataStores and how to use them.
Check for a certain time
Now we are done with that, let’s now check if a player’s time is on a certain amount. The best way to go about this would probably be to check in the same loop for a certain time. To do this as efficiently as possible. I would create a few table, like this:
local swordTimes = {
["The Great Sword"] = 100;
["The Better Sword"] = 500;
["The Awesome Sword"] = 1000;
-- Etc
}
In this table, we have 3 sword names. These sword names all have a time attached to them. Add as many words as you want and attach a time to them. Now we can check in the loop if the player is eligible for a sword. We can do that like this:
for _, swordTime in pairs(swordTimes) do
if timeInGame.Value == swordTime then
-- Hand the player the sword over
end
end
Now you can hand the player the sword over. I am not too sure if you already have a shop, but if not you can find some resources down below that might help you.
Resources
Resources for saving data
DataStoreService - A basic documentation about the functions of DataStoreService
How to use DataStores - A more in-depth documentation on how to use DataStores
DataStores Tutorial - After looking at the resources above, you could check out this tutorial if you don’t understand certain parts.
Resources for making the shop
RemoteEvents - For client-to-server communication
Tables - For saving the player’s swords
If Statements - To check for certain conditions
Resources for learning to script
Scripting Tutorial - A scripting course made by AvinBlox that teaches you step by step how to script on Roblox!
DevHub - A great place to find plenty of resources about specific scripting topics.