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

How do i get the mouses position so i can set the parts position to it when i left click?

Asked by 5 years ago
Edited 5 years ago
part = Instance.new("Part",game.Workspace)

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()

end)

1 answer

Log in to vote
0
Answered by 5 years ago

You can get the mouse position by getting the MouseObject and using Mouse.Hit.p. There is more information on it here: https://developer.roblox.com/api-reference/property/Mouse/Hit

To check if they left clicked, you would use Mouse.Button1Down event. More documentation here and sample codes: https://developer.roblox.com/api-reference/event/Mouse/Button1Down

However, I recommend using UserInputService as it is more modern and updated. More documentation here and sample codes: https://developer.roblox.com/api-reference/event/UserInputService/InputBegan

0
when i print the mouses position, it only prints it once, how would i have it print an updated positions every 3 seconds? DrDextrous -3 — 5y
0
The mouse position is already updated. Just call the position every time you click. If you still want it to do that, use a loops and wait(). PhantomVisual 992 — 5y
0
it just prints the same position over and over again DrDextrous -3 — 5y
0
even when i move my mouse to a different area DrDextrous -3 — 5y
View all comments (2 more)
0
Are you sure? It shouldn't work like that, you are probably doing something wrong. Don't store Mouse.Hit, you should be calling Mouse.Hit.p every time for the updated mouse position. PhantomVisual 992 — 5y
0
ok yea u were right, its working now. thank :) DrDextrous -3 — 5y
Ad

Answer this question