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

Gui won't budge?

local testFrame = script.Parent.Parent:FindFirstChild("testFrame")
local gui = script.Parent.Parent
local button = script.Parent
local px = testFrame.Position.X
local py = testFrame.Position.Y

function onClicked()
	while true do
		testFrame.Position = UDim2.new(px+1, py+1)
		wait(1)
	end
end

script.Parent.MouseButton1Click:connect(onClicked)

Maybe I over complicated it, maybe I'm doing it completely wrong, but how come my Gui won't move when the button is clicked? I figured CFrame was just for blocks so I switched to UDim2, no idea what it does but it was the recommended thing that the script does to guess what youre typing

1 answer

✓ Accepted answer

When you set the px and py variables, they check the position of the GUI, and don't change. To fix this you could put them inside of the loop:

local testFrame = script.Parent.Parent:FindFirstChild("testFrame")
local gui = script.Parent.Parent
local button = script.Parent

function onClicked()
	while true do
		local px = testFrame.Position.X
		local py = testFrame.Position.Y
		testFrame.Position = UDim2.new(px+1, py+1)
		wait(1)
	end
end

button.MouseButton1Click:connect(onClicked)

This would make the variables change each time it moves. Alternatively, you could use tweening to reposition GUIs, if you'd like.

Hope this helped.

2 comments

0

Thank you soooo much! :)

0

No problem.

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