Scripting Support for GUI - tweening issues

Hello, I have a few little problems and it’s do with the gui tweeing not repeating itself correctly after 2-3 tries.

Video:
https://streamable.com/prhiag

As you can see, on the 3rd try the tweeing fails.
After stopping recording, the high light menu only appeared not the alert. I’m not sure what breaks when you continously press the button.

Main code of issue:

alert = white highlight box around the item id box
Alerts = alert that pops in the bottom left

Full Code:

local Player = game.Players.LocalPlayer
local MarketService = game:GetService("MarketplaceService")
local IDBox = script.Parent.Parent.IDInput
local ConfirmPurchase = script.Parent.Parent.confirm
local TextConfirm = script.Parent.Parent.texxt
local ID
local green = script.Parent.Parent.texxtminus
local alert = script.Parent.Parent.alert

IDBox.FocusLost:Connect(function()
	ID = IDBox.Text
end)

ConfirmPurchase.MouseButton1Down:Connect(function()
	if ID ~= nil then
		local SuccessCheck, NotValid = pcall(function()
			MarketService:PromptPurchase(Player, ID)
		end)

		if SuccessCheck then
			print(Player.Name.." has inserted a valid Catalog ID")
			
			
		else
			
			script.Parent.Parent.Alerts.TextBox.Text = "That's not a valid Catalog ID!"
			script.Parent.Parent.Alerts.Visible = true
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(0.06,0,0.738,0),
				"In",
				"Bounce",
				.5,
				false

			)

			wait(3)
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(-0.237, 0,0.738, 0 ),
				"Out",
				"Bounce",
				.5,
				false

			)
			
			wait(3)
			script.Parent.Parent.Alerts.Visible = false
		end
	else
		--- if no value
		alert.Visible = true
		script.Parent.Parent.Alerts.TextBox.Text = "Please enter the ID of the item in the box first"
		script.Parent.Parent.Alerts.Visible = true
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(0.06,0,0.738,0),
			"In",
			"Bounce",
			.5,
			false
			
			)
		
		wait(3)
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(-0.237, 0,0.738, 0 ),
			"Out",
			"Bounce",
			.5,
			false
			
		)
		alert.Visible = false
		wait(3)
		script.Parent.Parent.Alerts.Visible = false
		
		
	end
	
	MarketService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
		if isPurchased == true then
            
			script.Parent.Parent.Alerts.TextBox.Text = "Successfully purchased!"
			script.Parent.Parent.Alerts.Visible = true
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(0.06,0,0.738,0),
				"In",
				"Bounce",
				.5,
				false

			)

			wait(3)
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(-0.237, 0,0.738, 0 ),
				"Out",
				"Bounce",
				.5,
				false

			)

			wait(3)
			script.Parent.Parent.Alerts.Visible = false
		
			
			
			
			
		else
			script.Parent.Parent.Alerts.TextBox.Text = "Failed to buy item"
			script.Parent.Parent.Alerts.Visible = true
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(0.06,0,0.738,0),
				"In",
				"Bounce",
				.5,
				false

			)

			wait(3)
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(-0.237, 0,0.738, 0 ),
				"Out",
				"Bounce",
				.5,
				false

			)

			wait(3)
			script.Parent.Parent.Alerts.Visible = false
		end
	end)
	
	
end)

If anyone could find me a way to fix this, so it loops perfectly everytime - I will be very thankful because I have no clue on how to solve this.

1 Like

Perhaps you got an error because you didn’t finish referring to ID?

local id

Try:
local id = DIRECTORYLOCATIONHERE

1 Like

No, the main purpose of the game works, but it’s the tweening that doesn’t loop correctly when you press the button multiple times.

Fixed by adding debounce, new script:

local Player = game.Players.LocalPlayer
local MarketService = game:GetService("MarketplaceService")
local IDBox = script.Parent.Parent.IDInput
local ConfirmPurchase = script.Parent.Parent.confirm
local TextConfirm = script.Parent.Parent.texxt
local ID
local green = script.Parent.Parent.texxtminus
local alert = script.Parent.Parent.alert
local debounce = false

IDBox.FocusLost:Connect(function()
	ID = IDBox.Text
end)

ConfirmPurchase.MouseButton1Down:Connect(function()
	if not debounce then
		debounce = true
		if ID ~= nil then
			local SuccessCheck, NotValid = pcall(function()
				MarketService:PromptPurchase(Player, ID)
			end)

			if SuccessCheck then
				print(Player.Name.." has inserted a valid Catalog ID")
				debounce = false
			else
				
				script.Parent.Parent.Alerts.TextBox.Text = "That's not a valid Catalog ID!"
				script.Parent.Parent.Alerts.Visible = true
				script.Parent.Parent.Alerts:TweenPosition(
					UDim2.new(0.06,0,0.738,0),
					"In",
					"Bounce",
					.5,
					false

				)

				wait(3)
				script.Parent.Parent.Alerts:TweenPosition(
					UDim2.new(-0.237, 0,0.738, 0 ),
					"Out",
					"Bounce",
					.5,
					false

				)
				
				wait(3)
				script.Parent.Parent.Alerts.Visible = false
				debounce = false
			end
		else
			--- if no value
			alert.Visible = true
			script.Parent.Parent.Alerts.TextBox.Text = "Please enter the ID of the item in the box first"
			script.Parent.Parent.Alerts.Visible = true
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(0.06,0,0.738,0),
				"In",
				"Bounce",
				.5,
				false
				
				)
			
			wait(3)
			script.Parent.Parent.Alerts:TweenPosition(
				UDim2.new(-0.237, 0,0.738, 0 ),
				"Out",
				"Bounce",
				.5,
				false
				
			)
			alert.Visible = false
			wait(3)
			script.Parent.Parent.Alerts.Visible = false
			
			debounce = false
		end
	end
	
end)

MarketService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
	if isPurchased == true then
        
		script.Parent.Parent.Alerts.TextBox.Text = "Successfully purchased!"
		script.Parent.Parent.Alerts.Visible = true
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(0.06,0,0.738,0),
			"In",
			"Bounce",
			.5,
			false

		)

		wait(3)
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(-0.237, 0,0.738, 0 ),
			"Out",
			"Bounce",
			.5,
			false

		)

		wait(3)
		script.Parent.Parent.Alerts.Visible = false
	
		
		
		
		
	else
		script.Parent.Parent.Alerts.TextBox.Text = "Failed to buy item"
		script.Parent.Parent.Alerts.Visible = true
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(0.06,0,0.738,0),
			"In",
			"Bounce",
			.5,
			false

		)

		wait(3)
		script.Parent.Parent.Alerts:TweenPosition(
			UDim2.new(-0.237, 0,0.738, 0 ),
			"Out",
			"Bounce",
			.5,
			false

		)

		wait(3)
		script.Parent.Parent.Alerts.Visible = false
	end
end)
1 Like