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)

1 comment
Thank you!