IntValue for Button tycoon

hello I’m doing a tycoon … but I have a problem … when I buy the button with an IntValue of $15 and I have $30 it takes 15+15 …
if I only have $15 and the Button costs $15 it works as it should …
when my problem is that when I buy and I have double he gets twice his value !!
xDr
I was wondering if there is a script that can tell the Value activated once.
or otherwise after you activate change your value to $0 .
or if you know other ways to fix!!

3 Likes

Can you show the script inside the button so it can be fixed?

3 Likes


in the button script there is a command to make it change color !!

  1. List item
    if buttons then
    for i, v in pairs(buttons:GetChildren()) do
    spawn(function()
    if v:FindFirstChild(“Button”) then

     		local newObject = purchasedItems:FindFirstChild(v.Object.Value)
     		if newObject  ~= nil then
     			objects [newObject.Name ] = newObject:Clone()
     			newObject:Destroy()
     		else
     			v:Destroy()
     		end
     		
     		if v:FindFirstChild("Dependency") then
     			v.Button.Transparency = 1
     			v.Button.CanCollide = false
     			v.Button.BillboardGui.Enabled = false
     			v.Button.BillboardGui2.Enabled = false
     			coroutine.resume(coroutine.create(function()
     				if tycoon.Purchases:WaitForChild(v.Dependency.Value) then
     					v.Button.Transparency = 0
     					v.Button.CanCollide = true
     					v.Button.BillboardGui.Enabled = true
     					v.Button.BillboardGui2.Enabled = true
     				end
     			end))
     		end
     		
     		v.Button.Touched:Connect(function(hit)
     			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
     			if player then
     				if values.OwnerValue.Value == player then
     					if v.Button.CanCollide == true then
     						if v:FindFirstChild("GamepassID")and v.GamepassID.Value >= 1 then
     							if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 241299882) then
     								objects [v.Object.Value].Parent =tycoon.Purchases
     								playSound(v, audio.buttonSound.SoundId)
     								v:Destroy()
     							else
     								MarketplaceService:PromptGamePassPurchase(player,241299882)
     							end
     							
     						elseif v:FindFirstChild("Rebirth") and v:FindFirstChild("Rebirth").Value then
     							if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
     								playSound(v, audio.buttonSound.SoundId)
     								player.leaderstats.Cash.Value -= v.Price.Value
     								objects[v.Object.Value].Parent = tycoon.Purchases
     								tycoon.Parent:FindFirstChild("RebirthTycoon"):Fire(player)
     								v:Destroy()
     							end
     						elseif v:FindFirstChild("RebirthPrice") and v:FindFirstChild("RebirthPrice").Value then
     							if player:FindFirstChild("leaderstats").Rebirths.Value >= v.RebirthPrice.Value then
     								playSound(v, audio.buttonSound.SoundId)
     								player.leaderstats.Rebirths.Value -= v.RebirthPrice.Value
     								objects[v.Object.Value].Parent = tycoon.Purchases
     								v:Destroy()
     							end
     							
     						elseif player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
     							player.leaderstats.Cash.Value -= v.Price.Value
     							objects [v.Object.Value].Parent =tycoon.Purchases
     							playSound(v, audio.buttonSound.SoundId)
     							v:Destroy()
     						else
     							playSound(v, audio.error.SoundId)
     						end
     					end
     				end
     			end
     		end)
     	end
     	tycoon.Purchases.ChildAdded:Connect(function(add)
     		animateBuildingIn(tycoon.Purchases:FindFirstChild(v.Object.Value), TweenInfo.new(1,Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)):Wait()
     	end)
     end)
    

    end
    end

1 Like

I don’t really understand what you want to do here, but I will try my best. If you want to have a cooldown, not just buying all of it instantly, then you can use a debounce to stop it from activating too much times.


if buttons then
	for i, v in pairs(buttons:GetChildren()) do
		if v:FindFirstChild("Button") then
			local debounce = false
			local debounceTime = 1

			local newObject = purchasedItems:FindFirstChild(v.Object.Value)
			if newObject  ~= nil then
				objects [newObject.Name ] = newObject:Clone()
				newObject:Destroy()
			else
				v:Destroy()
			end

			if v:FindFirstChild("Dependency") then
				v.Button.Transparency = 1
				v.Button.CanCollide = false
				v.Button.BillboardGui.Enabled = false
				v.Button.BillboardGui2.Enabled = false
				coroutine.resume(coroutine.create(function()
					if tycoon.Purchases:WaitForChild(v.Dependency).Value then
						v.Button.Transparency = 0
						v.Button.CanCollide = true
						v.Button.BillboardGui.Enabled = true
						v.Button.BillboardGui2.Enabled = true
					end
				end))
			end

			v.Button.Touched:Connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if debounce == true then return end -- if not done then stops it from running
				debounce = true
				if player then
					if values.OwnerValue.Value == player then
						if v.Button.CanCollide == true then
							if v:FindFirstChild("GamepassID")and v.GamepassID.Value >= 1 then
								if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 241299882) then
									objects [v.Object.Value].Parent =tycoon.Purchases
									playSound(v, audio.buttonSound.SoundId)
									v:Destroy()
								else
									MarketplaceService:PromptGamePassPurchase(player,241299882)
								end

							elseif v:FindFirstChild("Rebirth") and v:FindFirstChild("Rebirth").Value then
								if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
									playSound(v, audio.buttonSound.SoundId)
									player.leaderstats.Cash.Value -= v.Price.Value
									objects[v.Object.Value].Parent = tycoon.Purchases
									tycoon.Parent:FindFirstChild("RebirthTycoon"):Fire(player)
									v:Destroy()
								end
							elseif v:FindFirstChild("RebirthPrice") and v:FindFirstChild("RebirthPrice").Value then
								if player:FindFirstChild("leaderstats").Rebirths.Value >= v.RebirthPrice.Value then
									playSound(v, audio.buttonSound.SoundId)
									player.leaderstats.Rebirths.Value -= v.RebirthPrice.Value
									objects[v.Object.Value].Parent = tycoon.Purchases
									v:Destroy()
								end

							elseif player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
								player.leaderstats.Cash.Value -= v.Price.Value
								objects [v.Object.Value].Parent =tycoon.Purchases
								playSound(v, audio.buttonSound.SoundId)
								v:Destroy()
							else
								playSound(v, audio.error.SoundId)
							end
						end
					end
				end
				task.wait(debounceTime) -- wait
				debounce = false -- sets it back so it can be used again
			end)
		end
		tycoon.Purchases.ChildAdded:Connect(function(add)
			animateBuildingIn(tycoon.Purchases:FindFirstChild(v.Object.Value), TweenInfo.new(1,Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)):Wait()
		end)
	end

end

I removed spawn to make sure it doesn’t spam Touched too much, and you can change the debounceTime (wait time) to your preference.

2 Likes

I did a test on a button and it worked but now the problem is the Dependency
in the sense that it no longer performs its task

1 Like

one i added the spawn fuction and did 2 tests on 8 buttons and everything is fine, thanks for your help mate !!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.