Whenever I click "yes" to purchase the sword, it charges me twice and it gives me 2 swords. I'm not sure why it does this, but I also get blue underline where it says "yesConnect:disconnect", on line 28.
price = 10 plr = game.Players.LocalPlayer isowned = false script.Parent.MouseButton1Down:connect(function() local KOs = plr.leaderstats:WaitForChild("KOs") if KOs.Value > price and isowned == false then script.Parent.Parent.Visible = false script.Parent.Parent.Parent.AreYouSure.Visible = true local yesConnect yesConnect = script.Parent.Parent.Parent.AreYouSure.Yes.MouseButton1Down:connect(function() isowned = true KOs.Value = KOs.Value - price local sworda = game.ReplicatedStorage.NoobSword:Clone() sworda.Parent = plr.Backpack local swordb = game.ReplicatedStorage.NoobSword:Clone() swordb.Parent = plr.StarterGear script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false end) elseif isowned == true then print('already owned') end local noConnect noConnect = script.Parent.Parent.Parent.AreYouSure.No.MouseButton1Down:connect(function() script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false yesConnect:disconnect() noConnect:disconnect() end) end)
I'm not sure why it's giving you two swords each time, but I moved the noConnect
function inside the if
statement, and made the yesConnect
function disconnect both events:
price = 10 plr = game.Players.LocalPlayer isowned = false script.Parent.MouseButton1Down:connect(function() local KOs = plr.leaderstats:WaitForChild("KOs") if KOs.Value > price and isowned == false then script.Parent.Parent.Visible = false script.Parent.Parent.Parent.AreYouSure.Visible = true local yesConnect, noConnect yesConnect = script.Parent.Parent.Parent.AreYouSure.Yes.MouseButton1Down:connect(function() isowned = true KOs.Value = KOs.Value - price local sworda = game.ReplicatedStorage.NoobSword:Clone() sworda.Parent = plr.Backpack local swordb = game.ReplicatedStorage.NoobSword:Clone() swordb.Parent = plr.StarterGear script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false yesConnect:disconnect() noConnect:disconnect() end) local noConnect = script.Parent.Parent.Parent.AreYouSure.No.MouseButton1Down:connect(function() script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false yesConnect:disconnect() noConnect:disconnect() end) elseif isowned == true then print('already owned') end end)
I think your problem is that your local variables are in a function. Move them out of there and it should work ^.^
local yesConnect local yesConnect local noConnect price = 10 plr = game.Players.LocalPlayer isowned = false script.Parent.MouseButton1Down:connect(function() local KOs = plr.leaderstats:WaitForChild("KOs") if KOs.Value > price and isowned == false then script.Parent.Parent.Visible = false script.Parent.Parent.Parent.AreYouSure.Visible = true yesConnect = script.Parent.Parent.Parent.AreYouSure.Yes.MouseButton1Down:connect(function() isowned = true KOs.Value = KOs.Value - price local sworda = game.ReplicatedStorage.NoobSword:Clone() sworda.Parent = plr.Backpack local swordb = game.ReplicatedStorage.NoobSword:Clone() swordb.Parent = plr.StarterGear script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false end) elseif isowned == true then print('already owned') end noConnect = script.Parent.Parent.Parent.AreYouSure.No.MouseButton1Down:connect(function() script.Parent.Parent.Visible = true script.Parent.Parent.Parent.AreYouSure.Visible = false yesConnect:disconnect() noConnect:disconnect() end) end)