Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Tween service not working in if statement, what do I do?

When I was trying to script a line of code that made a UI slide to one position if it was in a specific position but if it was at the other position it will slide back to the other position.

I tried making it all in one script but then made it in two different scripts.

The First Script

local Button = script.Parent

if Button.Position == UDim2.new(1.483, 0,0.063, 0)
		
then Button:TweenPosition(
		UDim2.new(1.025, 0, 0.063, 0),
	"Out",
	"Sine",
	.2,
	false
	)
else script.Parent.LocalScript1.Disabled = false
	script.Disabled = true
		
end

Button.MouseButton1Up:Connect(function()
	
end)

The Second Script

if script.Parent.Position == UDim2.new(1.025, 0, 0.063, 0)

then script.Parent:TweenPosition(
	UDim2.new(1.483, 0, 0.063, 0),
	"Out",
	"Sine",
	.2,
	false
	)
else script.Parent.LocalScript.Disabled = false
	script.Disabled = true
end

script.Parent.MouseButton1Up:Connect(function()
	
end)

The first script solution

function onClicked()

script.Parent:TweenPosition(
		UDim2.new(1.025, 0, 0.063, 0),
	"Out",
	"Sine",
	.2,
	false
	)
script.Parent.LocalScript1.Disabled = false
	script.Disabled = true
	
	end
	
script.Parent.MouseButton1Click:Connect(onClicked)

The second script solution

function onClicked()

script.Parent:TweenPosition(
	UDim2.new(1.483, 0, 0.063, 0),
	"Out",
	"Sine",
	.2,
	false
	)
script.Parent.LocalScript.Disabled = false
	script.Disabled = true
	
end

script.Parent.MouseButton1Click:Connect(onClicked)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.