How to move GUI sideways?

Hi! I’ve been trying to make a GUI (more specifically an ImageLabel) move to the right when a script is run. Unfortunately, it keeps moving diagonally for some reason, even though I don’t want it to! If you need a better explanation, this is what I mean:


{75C01F29-F14D-4DEA-83B0-106A56AFF947}
If there’s any fix to this or workaround that I don’t know of, please let me know! And here’s the code for the script I made incase that helps:

local player = game.Players.LocalPlayer
local ui = player.PlayerGui:WaitForChild("BossIntro")
local remoteevent = game.ReplicatedStorage:WaitForChild("GUIEvent")

remoteevent.OnClientEvent:Connect(function(Player)
	ui.Enabled = true
	for i = 1, 10 do
		ui.UI.ImageLabel:TweenPosition(UDim2.new(0,50,0,0),"InOut","Linear",1)
		wait(0.05)
	end
end)

Since you’re repeatedly tweening to UDim2.new(0, 50, 0, 0) in a for loop, the positions stack as each tween completes, causing the diagonal motion. This may not be the best fix but this should work:

local player = game.Players.LocalPlayer
local ui = player.PlayerGui:WaitForChild("BossIntro")
local remoteevent = game.ReplicatedStorage:WaitForChild("GUIEvent")

remoteevent.OnClientEvent:Connect(function()

    ui.Enabled = true
	
	for i = 1, 10 do
		local currentPosition = ui.UI.ImageLabel.Position
		local newPosition = currentPosition + UDim2.new(0, 50, 0, 0)
		ui.UI.ImageLabel:TweenPosition(newPosition, "InOut", "Linear", 1)
		wait(0.05)
	end
	
end)
1 Like

Thank you so much! Don’t know why I didn’t think of that lol

1 Like

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