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

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

Asked by
KenzaXI 166
8 years ago

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

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
8 years ago

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!

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 KenzaXI 166 — 8y
Ad

Answer this question