Alright this is a simple problem, and should have a simple solution, but I cannot figure it out. The script below works perfectly, the button even fades away like I want it to(lines 26-29). However, if a player steps on the button again as the button is fading, the button will register as being pressed again and will subtract its price from the leaderstats once again. As a result, someone might pay double or triple the price for an object.
Any help on a solution to this would be appreciated. I just need to know the general direction that I need to go in to keep the button from being pressed more than once while fading in that one second of vulnerability. Thanks.
-------------------------
--Background info
--script.Parent is the button
--script.Parent.Parent is a model of all the buttons
--script.Parent.Parent.Parent is the whole tycoon model
--script.Parent.Parent.Parent.Products is a model of all the products that the buttons buy
-------------------------
repeat wait() until script.Parent.Product.Value~=nil
local product=script.Parent.Product.Value:clone()
script.Parent.Product.Value:remove()
local price=script.Parent.Price.Value
script.Parent.Name=script.Parent.ProductName.Value.." - "..price
if price==0 then
script.Parent.Name=script.Parent.ProductName.Value.." - Free!"
end
script.Parent.Head.Touched:connect(function(hit)
chr=hit.Parent
if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then
plr=game.Players:GetPlayerFromCharacter(chr)
if plr.Name==script.Parent.Parent.Parent.OwnerName.Value and plr.leaderstats.Money.Value>=price then
plr.leaderstats.Money.Value=plr.leaderstats.Money.Value-price
product.Parent=script.Parent.Parent.Parent
for i = 1, 10 do
script.Parent.Head.Transparency = script.Parent.Head.Transparency + .1
wait(.1)
end
script.Parent:remove()
end
end
end)

1 comment
Thanks a lot, this is my first time being introduced to debouncing. This will come in handy.