Summary: “Failed” ScreenGUI not appearing when part clicked and $ = 0 & both (“success” & “failed”) ScreenGUI’s showing up when only one should appear.
The “Failed to purchase” message for my shop doesn’t work correctly. When the player clicks on it with $0, it doesn’t show up. But when the player has enough $ to purchase, the success prompts shows up, but then the “Failed to purchase” prompt appears a few seconds afterward (even though the player has enough $).
local RequiredGold = script.Parent.Parent.Parent.Price.Value
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Shop["Health Potion"]
script.Parent.MouseClick:Connect(function(player)
if player.Data.Beli.Value >= RequiredGold then
player.Data.Beli.Value = player.Data.Beli.Value - RequiredGold
if not player.PlayerGui:FindFirstChild("Success") then
local Success = script.Success:clone()
Success.Parent = player.PlayerGui
wait(2)
tool:Clone().Parent = player.Backpack
player.Character.Humanoid:UnequipTools()
Success:Destroy()
end
if not player.PlayerGui:FindFirstChild("Failed") then
local Failed = script.Failed:clone()
Failed.Parent = player.PlayerGui
wait(2)
Failed:Destroy()
end
end
wait(2)
end)
Is there something I should add to my script to correct this bug/error?
Thank you for your help!