Hi, so I recently made a shop that gives players tools when clicked. It gives me multiple items. But how would I make it give me only one and not more forever?
This is the script that gives players tools (the “<>” are just placeholders of the tools I have, they have real names in the game):
game.ReplicatedStorage.ToolEvents.<ToolEventHere>.OnServerEvent:Connect(function(player)
if player.leaderstats.CafeCoins.Value >= 10 then
player.leaderstats.CafeCoins.Value = player.leaderstats.CafeCoins.Value - 10
game.ServerStorage.Tools.<ToolNameHere>:Clone().Parent = player.Backpack
end
end)
So I just want to make it one-time purchase to avoid players buying multiple items.
1 Like
You could save it as Player Data (which is just a table) you will then have to DataStore the PlayerData so that you can retrieve it when they join a new server.
DataStore tutorial
1 Like
Check if the Player’s Backpack/Character has the Tool in their inventory
game.ReplicatedStorage.ToolEvents.<ToolEventHere>.OnServerEvent:Connect(function(player)
if player.leaderstats.CafeCoins.Value >= 10 and player.Backpack:FindFirstChild("ToolNameHere") == nil and player.Character:FindFirstChild("ToolNameHere") == nil then
player.leaderstats.CafeCoins.Value = player.leaderstats.CafeCoins.Value - 10
game.ServerStorage.Tools.<ToolNameHere>:Clone().Parent = player.Backpack
end
end)
3 Likes
Wow, thanks! It worked for my game!
Uh okay, but that’s not going to save from server to server.
1 Like
Yes, but I just want the shop to not give people multiple items, and not storing them, but I could just script storages .
Okay, not sure how you are going to “script storages”.
if you want players to have something they bought the next time they join you will have to use DataStoreService or use an external database
1 Like