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

Why is this function failing to get the Gui's position?

Asked by 9 years ago

Every time I run this function and put the the Gui's position it creates the Points position at (0,0,0,0) why and how do I fix it?

Local Script(Updated):

local Player = game.Players.LocalPlayer
-----------------------------------------
function CreateGui()
local ScreenGui = Instance.new("ScreenGui",Player.PlayerGui)
    ScreenGui.Name = "Stuff"
local Frame = Instance.new("Frame",ScreenGui)
    Frame.Position = UDim2.new(0,350 ,0,200)
    Frame.Size = UDim2.new(0,100    ,0,100)
return Frame
end
-----------------------------------------
function CreatePoints(Position)
    print("Given Position for function CreatePoints() is: ",Position)
    -----------------
    function FindScreenGui()
    local Found = Player.PlayerGui:FindFirstChild("Stuff")
    if not Found then
        local ScreenGui = Instance.new("ScreenGui",Player.PlayerGui)
        return ScreenGui
    else 
        return Found
    end
    -----------------
    end
    local ScreenGui =  FindScreenGui()
    local Point = Instance.new("Frame",ScreenGui)
        Point.Position = Position
        Point.Size = UDim2.new(0,10 ,0,10)
--      Point.BackgroundColor = Color3.new(255/255,0/255,0/255)-- I'll fix part later
        return Point
end
-----------------------------------------
function GetCenterOfGui(Gui)

absoluteXS = Gui.AbsoluteSize.X
absoluteYS = Gui.AbsoluteSize.Y

absoluteXP = Gui.AbsolutePosition.X
absoluteYP = Gui.AbsolutePosition.Y
return UDim2.new(0, absoluteXP + (absoluteXS/2), 0, absoluteYP + (absoluteYS/2))
end
-----------------------------------------
local Gui = CreateGui()
--local Point = CreatePoints(UDim2.new(Gui.Position.X.Scale
--                          ,Gui.Position.X.Offset,
--                          Gui.Position.Y.Scale,
--                          Gui.Position.Y.Offset))
local Middle = GetCenterOfGui(Gui)
local Point = CreatePoints(Middle)

1 answer

Log in to vote
1
Answered by
Scubadoo2 115
9 years ago

When you get the Gui's position, it is returning two numbers, the Scale and the Offset. When you try to give it those numbers, it will just give it 0 (I don't know why). If you want to Offset to be in it, you have to use Gui.Position.X.Offset.

Basically, all you have to do is change the last line to this:

local Point = CreatePoints(UDim2.new(Gui.Position.X.Scale,Gui.Position.X.Offset,Gui.Position.Y.Scale,Gui.Position.Y.Offset))

I changes it so that it also has the Scale in it as well. Hopefully this helps.

0
Thanks,It worked and I mixed it with other question you helped with to get the middle of a GUI,but it doesn't look like it's the middle. kevinnight45 550 — 9y
0
Here is how the point came out: http://i.imgur.com/4WhLNQP.png?1?3328 kevinnight45 550 — 9y
1
OOOHH!!!! I messed up! I ADDED the Size instead of SUBTRACT it. That should fix it. Scubadoo2 115 — 9y
Ad

Answer this question