Sword Inventory & Shop | Help

Hey! I recently made a stay alive and get time game and I need your help to help me out with the Sword Inventory/Shop GUI where you can equip your sword and unequip and then when you hit that certain time, it’s automatically in your sword inventory

I want it like this

image

but the swords I want to put in my game is these swords in the replicated storage in my game
image

4 Likes

I am not too sure about the issue you’re trying to address here. Do you need help with creating the whole shop overall or with a specific part of it?

2 Likes

I wanna create the shop overall but when you hit that certain time you get the sword

2 Likes

Not done with writing yet, submitted it early sorry.

2 Likes

it’s alright but do you know how to do it?

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.

1 Like

I’m not very good at scripting but can you leave the scripts like which scripts go like where do
local timeInGame = Instance.new("IntValue") timeInGame.Name = "TimeInGame" timeInGame.Parent = player where does that go and also I have a DataStore if you don’t mind I can show you the script?

Earlier in the post, I already stated that the script belongs to ServerScriptService. I have noted plenty of resources that can help you started. I would recommend reading the whole post and checking out these resources. You’re supposed to find it out by yourself to learn, instead of getting the whole script without learning anything from it.

3 Likes