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

Localscript for Gui not working, and no errors in output?

Hi, this is the script:

local MGui = script.Parent.Parent.Parent
local Frame = MGui.Frame
local Atlass = Frame.Atlass
local Slider = script.Parent
Slider.MouseButton1Click:connect(function()
	if Frame.Position == UDim2.new({0, 4},{0, 150}) then
		Frame.Position = UDim2.new({0, -200},{0, 150})
	elseif Frame.Position == UDim2.new({0, -200},{0, 150}) then
	Frame.Position = UDim2.new({0, 4},{0, 150})
	end
end)

when it's clicked it should check if it's Position is {0, 4},{0, 150} and if it is then it should change it to {0, -200},{0, 150} or if it's the other way around then the opposite should happen however, It won't work. and I don't know why, This is the first time I've Used UDim2 and I don't know much about it. Thanks for your help.

1 answer

✓ Accepted answer

When using UDim2.new() in ROBLOX Lua, you do not put {} inside the parentheses.


Correct: UDim2.new(XScale, XOffset, YScale, YOffset)

Incorrect: UDim2.new({XScale, XOffset}, {YScale, YOffset})


Bearing that in mind, let's look at your script.


Fixed Code:

local MGui = script.Parent.Parent.Parent
local Frame = MGui.Frame
local Atlass = Frame.Atlass
local Slider = script.Parent
Slider.MouseButton1Click:connect(function()
    if Frame.Position == UDim2.new(0, 4,0, 150) then --None of the {}'s.
        Frame.Position = UDim2.new(0, -200,0, 150) --None of the {}'s.
    elseif Frame.Position == UDim2.new(0, -200,0, 150) then --None of the {}'s.
    Frame.Position = UDim2.new(0, 4,0, 150) --None of the {}'s.
    end
end)

Here is the Wiki page on UDim2.

If I helped you out, be sure to accept my answer!

1 comment

0

Cheers bro, I've done with with Vector3's and known not to put in {} within brackets, I can't believe this didn't come to me lol Thanks anyway

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