Mouse Dont Print Target Name how fix?

https://gyazo.com/f31c3c00bf22bde1b4eed2920cf2cdd0

idk what do

pls help

2 Likes

You’re only checking the target once.

1 Like

This might be because the if condition runs only once, meaning that the player’s mouse might not be pointing at a part when it runs once. To fix that you can use a loop like a while loop to continuously detect if the mouse is pointing at a part. Or you can use Mouse.Moved function but I found that very laggy when I used it.

So, use a while loop and put the if condition inside it. Make sure you are using wait in the loop.

While true do 

   If condition here
   Wait(0.001) < you need this!

end

Soo what the solution ???

https://gyazo.com/f31c3c00bf22bde1b4eed2920cf2cdd0

mouse.Button1Down:Connect(function()
    print(mouse.Target)
end)

like this???

https://gyazo.com/ef153e470e8c4e4755c334ce3a10cf09

nope doesent work

While true do

If condition here
Wait(0.001) < you need this!

end

while wait() do is not unstable in any way. wait will never not delay execution.

1 Like

I suspect this is something similar to what you’re wanting. The issue in your original script is that you’re only checking mouse.Target once, with this snippet, it’s checked every time you click. I’d recommend you check out the Developer Wiki article on the Mouse object and scroll down to “events”.

1 Like

i want when its point at it “Target” then print The Name of it

but why its not working i did it and its not printing nothing when i click something

Is it in a LocalScript or regular Script?

1 Like

its in local script i did that

can you make Example place for me?

Click.rbxl (14.8 KB)
The script is underneath StarterPlayerScripts.

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

mouse.Button1Down:Connect(function()

    if mouse.Target == Baseplate then
        print("The part is Baseplate")
    end
end)

Hope this helps
1 Like

thx now i undarstand thx you and for everyone else

2 Likes

yes i undarstand where is my mistake thx

1 Like

There’s a very different reason why what Carbyne said is appropriate. It is somewhat unstable, but not in the sense that wait has the potential to return a non-truthy value.

cc @TheCarbyneUniverse

1 Like

Thanks for the heads up! I think in this case while wait() do is perfectly fine, though. Could you elaborate on what you mean by unstable? I don’t see how a while wait() do loop could “break”.