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

how to get where the position of the mouse is pointed at?

so when using mouse i can't find out how to get the position of the thing that the mouse is pointing at i try to do

mouse.Hit.position

but it says "this mouse is no longer active"

4 comments

0

Are you getting the mouse as a parameter of a method of a tool, by any chance?

0

yes i am why??? ????

0

oop sorry for 8 question marks

0

so i put it in a local script and i did player:get mouse all of that stuff but i didn't use it before because when ever i use it, for some reason when i create a var called barrel it says that it is not in the tool i did script.parent.parent.barrel and it says it doesn't work it is so simple that i don't know how it is not working

1 answer

✓ Accepted answer

There are two solutions to this.

But first, we must address the problem at hand. You are getting this error because you are trying to use a mouse that is no longer active. This happens when you get the mouse as a parameter of the Equipped method of any Tool object.

The first solution would be to just get the mouse from the GetMouse method of the local player.

local players = game:GetSerivce("Players")
local localPlayer = players.LocalPlayer
local mouse = localPlayer:GetMouse()

The second solution would be to update the mouse every time the tool is equipped.

local mouse

tool.Equipped:Connect(function(givenMouse)
    mouse = givenMouse
end)

2 comments

0

i did that and it worked but there was a problem that came with changing it to a local script (see comment number 4)

0

nevermind i needed to do :WaitForChild("barrel") then i needed to do mouse.Hit.p then it worked!

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