In my Tycoon I have a button takes away the players iron (from leaderboard) and creates a block. When the player has iron, the button works as it should. If they hit the button while they have 0 iron by accident and then afterwards hit it when they do have iron, the button no longer works. Why is that? It's not showing any issues in the script output.
Upgradecost = 1 owner = script.Parent.Parent.Parent.OwnerName local debounce = false function onTouched(hit) if debounce then return end debounce = true check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then if hit.Parent.Name == owner.Value then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local Iron = stats:findFirstChild("Iron") if Iron.Value > (Upgradecost-1) then Iron.Value = Iron.Value - Upgradecost Part = Instance.new("Part", game.Workspace) Part.Anchored = false Part.CFrame = CFrame.new(-385.1, 8, -224) Part.Size = Vector3.new(1,1,1) Part.BrickColor = BrickColor.new(199) Part.Name = "Iron" wait(1) debounce = false end end end end end script.Parent.Touched:connect(onTouched)
Since your debounce isn't outside of the if Iron.Value > (UpgradeCost-1) then
code, your debounce will never be able to change if they don't have the money. Place the debounce = false
before the last end, which closes the function, and your script should work perfectly.
PS: Make sure to lay out your tabbing more clearly so you can see errors such as that debounce one. Since it wasn't tabbed properly, it was most likely the reason you missed it.