What do you want to achieve?
The “Repeat” ScreenGUI I added to my shop is triggered when it isn’t supposed to be triggered. How do I fix this problem in my script?
This pops up even though the player doesn’t actually own the item.
Then the “Failure” message pops up (which is supposed to happen because the player doesn’t have enough to buy the item).
What solutions have you tried so far?
I’ve looked into how debounce works and have been trying to rewrite my script but it still doesn’t work
local RequiredGold = script.Parent.Parent.Parent.Price.Value
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Shop["Star Sword"]
local debounce = false
script.Parent.MouseClick:Connect(function(player)
if debounce == false then
player.PlayerGui:FindFirstChild("Repeat")
local Repeat = script.Repeat:clone()
Repeat.Parent = player.PlayerGui
wait(2)
Repeat:Destroy()
else
end
if not debounce then -- Here is the debounce!
debounce = true
if player.Data.Beli.Value >= RequiredGold then
player.Data.Beli.Value = player.Data.Beli.Value - RequiredGold
player.PlayerGui:FindFirstChild("Success")
local Success = script.Success:clone()
Success.Parent = player.PlayerGui
wait(2)
tool:Clone().Parent = player.Backpack
player.Character.Humanoid:UnequipTools()
Success:Destroy()
else
if player.Data.Beli.Value <= RequiredGold then
player.PlayerGui:FindFirstChild("Failed")
local Failed = script.Failed:clone()
Failed.Parent = player.PlayerGui
wait(2)
Failed:Destroy()
end
debounce = false -- place is outside of the other function so it can restart the process.
end
end
end)
I would really appreciate it if someone could help me fix this error in my script since I’m very new to scripting and don’t know what’s going wrong.
local RequiredGold = script.Parent.Parent.Parent.Price.Value
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Shop["Star Sword"]
local debounce = false
script.Parent.MouseClick:Connect(function(player)
if debounce == false then
debounce = true
player.PlayerGui:FindFirstChild("Repeat")
local Repeat = script.Repeat:clone()
Repeat.Parent = player.PlayerGui
wait(2)
Repeat:Destroy()
debounce = false
end
if debounce then -- Here is the debounce!
debounce = true
if player.Data.Beli.Value >= RequiredGold then
player.Data.Beli.Value = player.Data.Beli.Value - RequiredGold
player.PlayerGui:FindFirstChild("Success")
local Success = script.Success:clone()
Success.Parent = player.PlayerGui
wait(2)
tool:Clone().Parent = player.Backpack
player.Character.Humanoid:UnequipTools()
Success:Destroy()
debounce = false
else
if player.Data.Beli.Value <= RequiredGold then
debounce = true
player.PlayerGui:FindFirstChild("Failed")
local Failed = script.Failed:clone()
Failed.Parent = player.PlayerGui
wait(2)
Failed:Destroy()
debounce = false
end
debounce = false -- place is outside of the other function so it can restart the process.
end
end
end)
local RequiredGold = script.Parent.Parent.Parent.Price.Value
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Shop["Star Sword"]
local debounce = false
script.Parent.MouseClick:Connect(function(player)
if debounce == true then
player.PlayerGui:FindFirstChild("Repeat")
local Repeat = script.Repeat:clone()
Repeat.Parent = player.PlayerGui
wait(2)
Repeat:Destroy()
else
end
if not debounce then -- Here is the debounce!
debounce = true
if player.Data.Beli.Value >= RequiredGold then
player.Data.Beli.Value = player.Data.Beli.Value - RequiredGold
player.PlayerGui:FindFirstChild("Success")
local Success = script.Success:clone()
Success.Parent = player.PlayerGui
wait(2)
tool:Clone().Parent = player.Backpack
player.Character.Humanoid:UnequipTools()
Success:Destroy()
else
if player.Data.Beli.Value <= RequiredGold then
player.PlayerGui:FindFirstChild("Failed")
local Failed = script.Failed:clone()
Failed.Parent = player.PlayerGui
wait(2)
Failed:Destroy()
end
debounce = false -- place is outside of the other function so it can restart the process.
end
end
end)
If I were to put
debounce = false
end
at the end then it’d trigger the GUI even though the player doesn’t have the item so instead I put “else” and everything seems to be working right!
Alright, well amazing, glad I was able to help, (even a little)!
If you need anything regarding this thread, you can always message me! And if you’d be so kind as to mark me as the solution, (to help the SEO), that would be fantastic!