Greetings,
I've made a gun shop, and at first sight works well, but after buying a gun the script clones the last gun and puts both in the player backpack. How can I solve it?
Scripts: Buy button script
--[[
Script made by: Time_URSS
Gui buttons and shopping
--]]
--//Variables\\--
local player = game.Players.LocalPlayer
local button = script.Parent
local name = button:WaitForChild("FinalName")
local price = button:WaitForChild("FinalPrice")
local nameText = button.Parent.Name
local priceText = button.Parent.Price
local replicatedStorage = game:GetService("ReplicatedStorage")
local verificationTab = button.Parent.Parent.Parent.Verification
--//Functions\\--
local function buyProcess()
local weapon = replicatedStorage:WaitForChild("Guns"):FindFirstChild(name.Value)
if weapon then
if player.leaderstats.Rubbles.Value >= price.Value then
verificationTab.Visible = true
verificationTab.Yes.MouseButton1Click:Connect(function()
verificationTab.Visible = false
player.leaderstats.Rubbles.Value = player.leaderstats.Rubbles.Value - price.Value
local clonedWeapon = weapon:Clone()
clonedWeapon.Parent = player.Backpack
print("Gun successfully bought, transaction ended well.")
end)
verificationTab.No.MouseButton1Click:Connect(function()
verificationTab.Visible = false
warn("Gun failed to be bought, transaction cancelled.")
end)
else
warn("Player does not have enough Rubbles to buy the gun. Wait until you've enough.")
end
else
error("Weapon not found, please contact Time_URSS to fix the error. ERROR#050")
end
end
button.MouseButton1Click:Connect(buyProcess)
Both buttons script
--[[
Script made by: Time_URSS
Gui buttons and shopping
--]]
--//Variables\\--
local player = game.Players.LocalPlayer
local button = script.Parent
local buybutton = button.Parent.Parent.Information.Buy
local priceText = button.Parent.Parent.Information:WaitForChild("Price")
local nameText = button.Parent.Parent.Information:WaitForChild("Name")
--//Values\\--
local name = button:WaitForChild("Name")
local description = button:WaitForChild("Description")
local characteristics = button:WaitForChild("Characteristics")
local price = button:WaitForChild("Price")
--//Functions\\--
local function onClicked()
print("Attempted to buy the "..name.Value..".")
priceText.Text = "Price: "..price.Value
nameText.Text = "Name: "..name.Value
buybutton:WaitForChild("FinalPrice").Value = price.Value
buybutton:WaitForChild("FinalName").Value = name.Value
end
button.MouseButton1Click:Connect(onClicked)
I hope I get help

3 comments
Keep in mind as soon as you press Yes or No, neither button will work afterwards until Button is pressed, again.
I broke both events because I figured if you press Yes, then No serves 0 purpose. Of course you can change this
Now the buttons are not working.