Hello there,
I’m trying to make a tower defense game. I already make the towers and the enemies. It all work perfectly until there’s an error in my output. It says HumanoidRootPart is not a valid member of Model
. I don’t know why. I tried adding an if
line but it’s gonna break the for
loop.
Here are the code:
function Round.patrol(map,enemy)
local humanoid = enemy:WaitForChild("Humanoid")
local paths = map.Paths
-- using tween service method
local TweenService = game:GetService("TweenService")
for i=1, #paths:GetChildren() do
if i > 1 then
local at = enemy.HumanoidRootPart.Position
local lookAt = paths[i].Position
local cframe = CFrame.lookAt(at,lookAt)
local tween = TweenService:Create(enemy.HumanoidRootPart.BodyGyro,TweenInfo.new(0.5),{CFrame = cframe})
tween:Play()
tween.Completed:Wait()
end
local distance = (enemy.HumanoidRootPart.Position - paths[i].Position).Magnitude
local tweenInfo = TweenInfo.new(
distance / enemy.Humanoid.WalkSpeed,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false,
0
)
local offset = enemy["Left Leg"].Size.Y + (enemy.HumanoidRootPart.Size.Y/2)
local cframe = paths[i].CFrame * CFrame.new(0,offset,0)
local tween = TweenService:Create(enemy.HumanoidRootPart,tweenInfo,{CFrame = cframe})
tween:Play()
tween.Completed:Wait()
end
-- deal damage
local damage = enemy.Humanoid.MaxHealth
map.Base.Humanoid:TakeDamage(damage)
-- destroy enemy
events.destroyHealthGui:FireAllClients(enemy.Head)
enemy:Destroy()
end
Please tell me how to fix it. I appreciate your helps. :]