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

Help with checking the mouses target?

Asked by
FiredDusk 1466 Moderation Voter
6 years ago

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)

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. User#2146 0 — 6y
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. chess123mate 5873 — 6y

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

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)
Ad

Answer this question