Unfortunately :GetPropertyChangedSignal() does not return an RBXScriptSignal which fires when the mouse’s “Target” property changes, you need to to listen to the mouse’s “.Move” event and determine if the mouse has a target from there instead.
local players = game:GetService("Players")
local player = players.LocalPlayer
local team = player.Team
local mouse = player:GetMouse()
mouse.Move:Connect(function()
local targetPart = mouse.Target
if targetPart then
local targetModel = targetPart:FindFirstAncestorOfClass("Model")
if targetModel then
local targetPlayer = players:GetPlayerFromCharacter(targetModel)
if targetPlayer then
if player ~= targetPlayer then
if targetPlayer.Team == team then --Targeted player is on the same team.
--Make crosshair green.
elseif targetPlayer.Team ~= team then --Targeted player is on an enemy team.
--Make the crosshair red.
end
end
end
end
end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local team = player.Team
local mouse = player:GetMouse()
local crosshair = script.Parent
mouse.Move:Connect(function()
crosshair.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
local targetPart = mouse.Target
if targetPart then
local targetModel = targetPart:FindFirstAncestorOfClass("Model")
if targetModel then
local targetPlayer = players:GetPlayerFromCharacter(targetModel)
if targetPlayer then
if player ~= targetPlayer then
if targetPlayer.Team == team then
crosshair.BackgroundColor3 = Color3.new(0, 1, 0)
elseif targetPlayer.Team ~= team then
crosshair.BackgroundColor3 = Color3.new(1, 0, 0)
end
else
crosshair.BackgroundColor3 = Color3.new(1, 1, 1)
end
else
crosshair.BackgroundColor3 = Color3.new(1, 1, 1)
end
else
crosshair.BackgroundColor3 = Color3.new(1, 1, 1)
end
else
crosshair.BackgroundColor3 = Color3.new(1, 1, 1)
end
end)