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

How to have two different GUIs make another move toward them when clicked?

Asked by 6 years ago

I made three different frames, two with buttons. The buttons are supposed to make the third frame move towards them. Although the GUI moves, it only moves to ayy.Position, even though I clicked on the other GUI.

This is the script under one of the frames with the buttons:

local plr = game:GetService("Players").LocalPlayer 

local gui = plr.PlayerGui:WaitForChild("THING")



script.Parent.MouseButton1Click:Connect(function()



    gui.Moving:TweenPosition(UDim2.new(gui.ayy.Position), "Out", 4)

    wait(1)

end)

--THING is a screenGui, Moving is the Gui that is supposed to move, and ayy is the gui it's supposed to move to

This is the other:

script.Parent.MouseButton1Click:Connect(function()


    local plr=game.Players.LocalPlayer

    local gls=plr.PlayerGui:WaitForChild("THING")

    gls.Moving:TweenPosition(UDim2.new(gls.Oot.Position), "Out", 4 )
end)

--THING is a screenGui, Moving is the Gui that is supposed to move, and Oot is the gui it's supposed to move to

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

I mimicked your frame setup, and was able to get it to function properly. For easier use, I put a local script inside "THING" that checks for either button to be pressed, instead of two different scripts for each button. If you wish to have a script within each button instead, by all means.

local plr = game:GetService("Players").LocalPlayer
local gui = plr.PlayerGui:WaitForChild("THING")

gui.ayy.TextButton.MouseButton1Click:Connect(function()

    gui.Moving:TweenPosition(UDim2.new(gui.ayy.Position.X,gui.ayy.Position.Y),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,2,true)
-- I believe this was your issue. Using your script just moved the gui's to 0,0,0,0. Position.X and position.Y are the scale and offset for each value, (X is 0,0, Y is the second set of 0,0)
    wait()
end)


gui.Oot.TextButton.MouseButton1Click:Connect(function()

    gui.Moving:TweenPosition(UDim2.new(gui.Oot.Position.X,gui.Oot.Position.Y),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,2,true)
    wait()
end)
Ad

Answer this question