I have a script for a tower defense game and the towers' attack functions use the CFrame.Lookat() functions to look at enemies, but I don't want it to look up/down, just left/right. So, I want the orientation's Y axis of the HumanoidRootPart to change but not the X axis. Here's my script (This is a module script):
function towerModule.Attack(tower, player)
local stats = tower:WaitForChild("stats")
local target = FindTarget(tower, info.Range.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local hum = target.Humanoid
animateTowerEvent:FireAllClients(tower, "Attack")
local targetCFrame = CFrame.lookAt(tower.HumanoidRootPart.Position,target.HumanoidRootPart.Position) --Here, I just need to edit the local targetCFrame to only change the Y axis orientation, but I don't know how to.
tower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
local oldTargetHealth = hum.Health
if stats.Damage.Value <= hum.Health then
hum:TakeDamage(stats.Damage.Value)
elseif stats.Damage.Value > hum.Health then
hum.Health = 0
end
local newTargetHealth = hum.Health
player.Stats.Money.Value += oldTargetHealth-newTargetHealth
if hum.Health <= 0 then
player.Stats.Kills.Value += 1
end
task.wait(stats.Cooldown.Value)
end
task.wait()
if tower and tower.Parent then
towerModule.Attack(tower, player)
end
end

1 comment
This worked, thank you!