idk if optimize is the right word lol, but so I just coded this thing for my game and honestly, I struggled with it and barely got it to work and the only issue is that it causes a LOT of lag. Basically though when a players mouse targets an enemy then I just wanna put this triangle-shaped part over the targets head and then if they move off of it then I wanna remove it. I think I had the right idea, but I just didn’t execute it properly smh
mouse.Move:Connect(function()
if deb == true then
deb = false
if mouse.Target ~= nil and workspace.Enemies:FindFirstChild(mouse.Target.Parent.Name) then
if isAttacking == true then
if createMarker == true then
createMarker = false
--print("TEST 1")
local hover = workspace.Enemies:FindFirstChild(mouse.Target.Parent.Name)
if not workspace.Temp:FindFirstChild("Marker") then
--print("TEST 2")
local marker = repStorage.Models.Marker
local markerClone = marker:Clone()
markerClone.Position = hover.Head.Position + Vector3.new(0,3,0)
markerClone.Parent = workspace.Temp
end
end
end
else
if workspace.Temp:FindFirstChild("Marker") then
workspace.Temp:FindFirstChild("Marker"):Destroy()
createMarker = true
end
end
deb = true
end
end)