Hi I have this gun that I scripted using mouse.Target however it only works when you aim at the NPCs head
I’m pretty sure the issue is not the NPC since I’ve tried multiple NPCs but maybe it could be?
When the cursor is red that means it has found a target, however you can see that it is white when aiming at different body parts and the mouse.target is actually the baseplate for some reason
Output of mouse.target:
Code:
while task.wait(0.03) do
game.Players.LocalPlayer.PlayerGui.GUI.Crosshair.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
if currentTarget ~= mouse.Target then
currentTarget = mouse.Target
if mouse.Target and mouse.Target:FindFirstAncestorOfClass("Model") then
if mouse.Target:FindFirstAncestorOfClass("Model"):FindFirstChild("Killer") then
changeCol(Color3.fromRGB(255, 0, 0))
else
changeCol(Color3.fromRGB(255, 255, 255))
end
else
changeCol(Color3.fromRGB(255, 255, 255))
end
end
if script.Parent.Parent.Parent.Parent ~= game.Players.LocalPlayer.Character then
break
end
end
-- You need this on top
local userInputService = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local runService = game:GetService("RunService")
-- Use RenderStepped for crosshair position
runService.RenderStepped:Connect(function()
local mouse = userInputService:GetMouseLocation()
game.Players.LocalPlayer.PlayerGui.GUI.Crosshair.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
end)
-- Connect a function to mouse.Move
mouse.Move:Connect(function()
if mouse.Target and mouse.Target:FindFirstAncestorOfClass("Model") then
if mouse.Target:FindFirstAncestorOfClass("Model"):FindFirstChild("Killer") then
changeCol(Color3.fromRGB(255, 0, 0))
else
changeCol(Color3.fromRGB(255, 255, 255))
end
else
changeCol(Color3.fromRGB(255, 255, 255))
end
end)