Finding object at center of the screen

Hi,

I am trying to find the object at the center of the screen when the player puts the crosshair over it so the player can pickup. Would the code be client or server side? does anyone have examples of the best way of doing this? Thanks

Example

2 Likes

It would be client-side, since the mouse is only there for the client and cannot be accessed server-side. I would suggest trying mouse.Target to detect what the mouse is pointing at.

local runService = game:GetService("Run Service")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
runService.RenderStepped:Connect(function()
    if mouse.Target then
        print(mouse.Target.Name)
    end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.