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

Help with checking the mouses target?

This is a very simple mistake I must be missing.. I am trying to make to when the mouse's target is not nil then, it prints 'a'

--// I get the mouse and other vars up here
game:GetService('RunService').RenderStepped:Connect(function()
    local XPos = Mouse.X
    local YPos = Mouse.Y
    if Mouse.Target ~= nil then
        print'a'
    end
end)

2 comments

1

That's strange, I put this exact code inside of a ServerScript and a LocalScript - but in PlayerGui and it works. "Make sure it's inside of the player somewhere" Is the only help I can provide.

0

FYI, if you're not in Play Solo, you need to be in a LocalScript to use RenderStepped. I recommend having 'print' statements throughout the script to make sure that it's running, that 'Mouse' exists, and that RenderStepped is firing.

1 answer

✓ Accepted answer

Yea RenderStepped can do that sometimes, in my experience I could only have RenderStepped in one place, adding it in more than one place would cause one of them to not work or some other unexpected thing happen.

Instead of doing that why would check only when your mouse is moving, it would be more efficient too.

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Move:connect(function()
	local XPos = mouse.X
    local YPos = mouse.Y
    if mouse.Target ~= nil then
        print'a'
    end
end)

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