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

I have a image that when I click it supposed to be exactly at mouse position but it wont, why?

Asked by
ojinga -14
5 years ago
game:GetService("UserInputService").InputChanged:connect(function(Input)

if Input.UserInputType == Enum.UserInputType.MouseMovement and Dragging == true then
    inputPosition = UDim2.new(0, Mouse.X-25, 0, Mouse.Y-25)
end

end)

I even tried to set it too.

game:GetService("UserInputService").InputChanged:connect(function(Input)

if Input.UserInputType == Enum.UserInputType.MouseMovement and Dragging == true then
    inputPosition = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end

end)

And changing the pictures anchor points to .5,.5 but no matter what if your windows size is changed the image ends up on the wrong position.

InputPosition is the images position.

heres a gif of what it does https://gfycat.com/RecentDesertedJunco

and when I do change it to fit my screen if I make the window smaller it messes up. How do I fix it so it stays same place no matter window size

0
mouse.Button1Down <-- use that mouse.Button1Down:Connect(function() greatneil80 2647 — 5y
0
use :Connect() not :connect() WideSteal321 773 — 5y
0
that will fix the problem ojinga -14 — 5y
0
no User#23365 30 — 5y
0
A D V I C E, also you could use UserInputService for detecting mouse input User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Try this in a LocalScript

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while true do
    local xm = mouse.X
    local ym = mouse.Y
    script.Parent.Position = UDim2.new(0, xm, 0, ym)
    wait()
end

Unfortunately, the Mouse Position can only be read using the offset, rather than the scalar Vector3 properties.

However, you could try this, which would take into account the mouse's position in relation to the absolute screen size, but is an estimation of the placement.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while true do
    local xm = mouse.X
    local ym = mouse.Y
    local xg = script.Parent.AbsoluteSize.X
    local yg = script.Parent.AbsoluteSize.Y
    script.Parent.Position = UDim2.new((1-(xg/xm)), 0, (1-(yg/(2*ym))), 0)
    wait()
end
Ad

Answer this question