Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui won't budge?

Asked by 8 years ago
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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

0
Thank you soooo much! :) Squidier 40 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad

Answer this question