i have a script that rotate the enemies to left or right base on where the player is from the object space
local TagService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local Players = game.Players
for _,enemies in pairs(TagService:GetTagged("Enemies")) do
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
RunService.Stepped:Connect(function()
local PlayerPosition = enemies.HumanoidRootPart.CFrame:ToObjectSpace(char.HumanoidRootPart.CFrame)
if PlayerPosition.Z > 0 then
enemies.HumanoidRootPart.Orientation = Vector3.new(0,-90,0)
else
enemies.HumanoidRootPart.Orientation = Vector3.new(0,90,0)
end
end)
end)
end)
end
the problem is this:
it seems to be the if else statement but i don’t know how to solve it.
Have you tried print debugging? Check if the if statements actually run by adding a print to it.
Also, for your case, can’t you just make use of CFrame.lookAt?