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)
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.