Hihi! So am tryna make a Gun System but I cant figure out how do I make the cursor icon red when the mouse hovers over a player/character/humanoid.
Is there any way I could do this?
Hihi! So am tryna make a Gun System but I cant figure out how do I make the cursor icon red when the mouse hovers over a player/character/humanoid.
Is there any way I could do this?
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Target = Mouse.Target
if Target and Target.Parent:FindFirstChild("Humanoid") then
print(Target)
end
And you just need to have a loop or renderstepped checking mouse target.
Or attach it to a Mouse.Move event so it doesnt fire as much as renderstepped
If you do this a player that moves in front of the mouse when the mouse isn’t moving won’t change the cursor icon.
Fair enough, you would need a loop so the mouse.Target updates regularly
Took @realmile 's script and modified it a bit so it finds a humanoid in the model the mouse is pointing too
local Run = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
Run.RenderStepped:Connect(function()
local Target = Mouse.Target
if Target and Target:FindFirstAncestorOfClass("Model") then
local model = Target:FindFirstAncestorOfClass("Model")
print(Target)
if model:FindFirstChild("Humanoid") then
--do stuff
end
end
end)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local FilterParams = RaycastParams.new()
FilterParams.FilterDescendantsInstances = {Player.Character}
RunService.RenderStepped:Connect(function()
local Ray = Camera:ViewportPointToRay(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
local Result = workspace:Raycast(Ray.Origin, Ray.Direction * 1000, FilterParams)
if Result then
local Target = Result.Instance
local Character = Target:FindFirstAncestorWhichIsA("Model")
if Character then
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
--its a player
end
end
end
end)
This should be all you need. It uses UserInputService instead of the mouse object as the mouse object has been superseded by that service.
The only issue with this is that it only works in first person since it tracks middle of the screen instead of mouse position, im not sure if you could even find mouse position without mouse object :\
UserInputService:GetMouseLocation()
Their not gonna supersede something without replacements.
Ah thanks a lot man! Ima try this now