Arlenox
(Arlenox)
July 19, 2022, 12:54am
#1
Hello! I am currently working on a pet UI for my game but I’m facing an issue positioning a frame to the client’s mouse position.
-- This is my current code
Frame.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
Expected result:
Current result:
I tried following instructions from all the topics below but none of them worked for me.
I am trying to set the frames Position to my mouse’s current position. But I am getting an error while doing so. Here is my current code.
for _, buttons in ipairs(script.Parent:GetDescendants()) do
if buttons:IsA('TextButton') or buttons:IsA('ImageButton') then
buttons.MouseButton1Click:Connect(function()
CircleEffect.Position = mouse.Hit.Position
end)
end
end
Any help will be apperciated.
Hello!
I have recently been trying to position a frame wherever the player clicks
Here’s what I did:
OBJECT HIERARCHY:
StarterGui/ScreenGui
StarterGui/ScreenGui/Button
StarterGui/ScreenGui/Button/LocalScript
StarterGui/ScreenGui/Button/Frame
Then I tried two methods…
First one was relatively simple:
local button = script.Parent
local frame = button:WaitForChild("Frame")
local userInputService = game:GetService("UserInputService")
button.MouseButton1Click:Connect(function()
…
Off we start I want to mention that I know there are already plenty of discussions on this problem but I’ve gone and read most of them and none seem to work for my case. As title already suggests - I am trying to set the frame position to the exact position of mouse when player clicks (for drag and drop system)
[image]
All those frames are in Inventory > InventoryFrame > Items but get moved to Inventory > InventoryFrame on click because I can’t move them if they are in Inventory > InventoryFra…
So I have been trying to set the gui textlabel’s position as my cursor’s position
cloneHealth.TextLabel.Position = UDim2.new(0, cursor.Hit.p.X , 0, cursor.Hit.p.Y)
I saw people trying to do this but their solution doesn’t seem to work for me ( idk why ), I need help!!! Thanks
Any help is appreciated!
2 Likes
Try to use scale and not offset.
I’ve also got something to work and it stays in the same position as your mouse
Code:
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Move:Connect(function()
script.Parent.Frame.Position = UDim2.new(mouse.X/mouse.ViewSizeX, 0, mouse.Y/mouse.ViewSizeY, 0)
end)```
Arlenox
(Arlenox)
July 19, 2022, 1:56am
#3
Is the frame a child of some other frame? Because if so the mouse’s 0,0 position is at the top left of the screen, while the frame’s 0,0 position is at the top left of its parent.
If that’s the issue you can fix by subtracting the parent’s AbsolutePosition from the mouse position.
5 Likes