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

Frames dosent add in right position?

I am trying to make a game were you add frames on click so once you click there will pop out a frame but once i click they intstence in diffrent position were i clicked

local mouse = player:GetMouse()


mouse.Button1Down:Connect(function()
local dot = Instance.new("Frame")
dot.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
dot.Position = UDim2.new(mouse.Y / 1000 ,0, mouse.X / 1000 ,0)
dot.Size = UDim2.new(0, 10, 0, 10) 
dot.Parent = game.StarterGui.ScreenGui.Frame
end)

1 answer

Before I try to answer I want to say I am on my phone so sorry if this is spelt weird or you see any spelling errors

The main issue I see right away is you’re using a very weird position for the gui object

Try:

local mouse = player:GetMouse()


mouse.Button1Down:Connect(function()
local dot = Instance.new("Frame")
dot.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
dot.Position = UDim2.new(mouse.X/ game.workspace.CurrentCamera.ViewportSize.X,0, mouse.Y/game.workspace.CurrentCamera.ViewportSize.Y,0)
dot.Size = UDim2.new(0, 10, 0, 10) 
dot.Parent = game.StarterGui.ScreenGui.Frame
end)

4 comments

0

This will get your screen size no matter the size and should place it in the right position, I also forgot to mention in the udim2 you had your X and Y mixed up

0

it shows me this error ViewportSizeX is not a valid member of Camera

0

@kristupas12344 change it to ViewportSize.X

0

My bad, was a mistake, i'll edit it to the correct thing

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