Hello! I'm trying to make a shop gui. Here's what I want to happen:
When the player opens the shop, they can see the swords available and click "Unlock" on the sword they want.
It'll check their level, and if they have the required level, itll change the button text to "Unlocked!" and give them the weapon in their backpack, and give it to them in their StarterGear so they get it when they respawn, and don't have to click the button again.
If their level requirement isn't met, it'll tell them "Insufficient level" and then change back to the old button name.
Here is the GUI: https://imgur.com/a/t0dfhUZ
And here is my code:
local player = game.Players.LocalPlayer
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
local level = player.leaderstats.Level
tool = game.ReplicatedStorage.Shop_Items.Cutlass
local db = true --debounce
local price = 1 --required level for item
function buy()
db = false
if level.Value >= price then
local a = tool:clone()
a.Parent = player.Backpack
local b = tool:clone()
b.Parent = player.StarterGear
script.Parent.Text = ("Unlocked!")
else
script.Parent.Text = ("Insufficient Level!")
wait(3)
script.Parent.Text = ("Unlock (Lvl 5)")
end
end
script.Parent.MouseButton1Down:connect(buy)
The script changes the name to Unlocked, and gives the player the sword as I want. HOWEVER:
When the player dies it changes it back to the the previous name, "Unlock (Lvl 5)" and doesn't keep it at "Unlocked!"
The player doesn't spawn with the new sword, even though its added to StarterGear.
The player can click it multiple times, How do I make it so the player can only click the button once per life?
This also creates many duplicate items in the StarterGear folder, (if I spam the button there's tons of swords there.) How can I remove duplicate items from StarterGear?
How could I fix these issues? Thank you very much for any help!
