Tower Defense Enemy Moving Issue

  1. What do you want to achieve? I want the enemies correctly be on the Y pos

  2. What is the issue? The enemies are half on the ground as you can see here
    Captura de pantalla 2025-01-02 164341

  3. What solutions have you tried so far? To try to fix this i added this attachment on the primary part


    i dont know how to change the script so this can work

im using Suphi Khaner tower defense tutorial, i know he said to move the humanoid root part down but i dont wanna do that

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local enemies = {}
local parts = {}
local cFrames = {}

local class = {}
class.__index = class

function class.start()
	shared.Task.PostTicks:Connect(BulkMove)
end

function class.new(name)
	local index = #enemies + 1
	local gamemodeEnemy = ReplicatedStorage.Assets.Characters.Enemies:FindFirstChild("Misc")
	
	local storedEnemyFolder = gamemodeEnemy:FindFirstChild(name)
	local model = storedEnemyFolder:FindFirstChildOfClass("Model")
	local nodeAttachment = model.PrimaryPart:FindFirstChild("Node")
	
	if not model then
		warn("This enemy doesn't exist:", name)
		return nil
	end
	
	if not model.PrimaryPart then
		warn("This enemy has no PrimaryPart:", name)
		return nil
	end
	
	if not nodeAttachment then
		warn("Node attachment is missing in:", name)
		return nil
	end
	
	if not nodeAttachment:IsA("Attachment") then
		warn("Node attachment is not an attachment:", name)
		return nil
	end
	
	local animSaves = model:FindFirstChild("AnimSaves")
	
	if animSaves then
		animSaves.Parent = nil
		animSaves:Destroy()
	end
	
	local self = setmetatable(model:GetAttributes(), class)
	self.Index = index
	self.WaypointIndex = 1
	self.CFrameIndex = 1
	self.Waypoint = shared.Node.Waypoints[self.WaypointIndex]
	self.CFrame = shared.Node.CFrames[self.CFrameIndex]
	self.Model = model:Clone()
	self.Model.PrimaryPart.CFrame = self.CFrame
	self.Model.Parent = workspace.Characters.Enemies
	self.NodeAttachment = self.Model.PrimaryPart:FindFirstChild("Node")
	
	local walkAnimation = self.Model.Animations.Walking:FindFirstChild("Walk")
	
	if self.Speed == 0 then
		warn("Speed is set to 0 for:", name, "- Is this intentional?")
	end
	
	if walkAnimation then
		if walkAnimation.AnimationId and walkAnimation.AnimationId ~= "" then
			self.Animation = self.Model.AnimationController.Animator:LoadAnimation(walkAnimation)
			self.Animation:Play(nil, nil, self.Speed * self.AnimationSpeed)
		else
			warn("Walk animation ID is missing for:", name)
		end
	else
		warn("Walk animation object is missing for:", name)
	end
	
	self.TickConnection = shared.Task.OnTick:Connect(Step, self)
	self.Destroyed = false
	
	enemies[index] = self
	parts[index] = self.Model.PrimaryPart
	cFrames[index] = self.Model.PrimaryPart.CFrame
	
	self.Waypoint:AddCharacter(self)
	return self
end

function class:Destroy()
	if self.Destroyed == true then return end
	
	self.TickConnection:Disconnect()
	self.Model:Destroy()
	self.Destroyed = true
	
	local lastEnemy = table.remove(enemies)
	
	if self == lastEnemy then
		table.remove(parts)
		table.remove(cFrames)
	else
		enemies[self.Index] = lastEnemy
		parts[self.Index] = table.remove(parts)
		cFrames[self.Index] = table.remove(cFrames)
		lastEnemy.Index = self.Index
	end
end

function Step(self)
	local waypointIndex = shared.Node:GetWaypointIndex(math.floor(self.CFrameIndex))
	
	self.CFrameIndex += self.Speed
	self.CFrame = shared.Node.CFrames[math.floor(self.CFrameIndex)]
	
	while self.WaypointIndex ~= waypointIndex do
		self.WaypointIndex += 1 -- math.sign(waypointIndex - self.WaypointIndex)
		self.Waypoint = shared.Node.Waypoints[self.WaypointIndex]
		self.Waypoint:AddCharacter(self)
		
		if self.Destroyed == true then return end
	end
	
	if self.CFrame == nil then
		self:Destroy()
	end
	
end

function BulkMove()
	for index, enemy in enemies do
		cFrames[index] = enemy.CFrame
		workspace:BulkMoveTo(parts, cFrames, Enum.BulkMoveMode.FireCFrameChanged)
	end
end

return class
2 Likes

It looks like the HipHeight of the Enemy is set wrong. If the enemies are standard 2 stud leg height then set HipHeight of the Humanoid to 2.

oh, i forgot to mention that this doesn’t use humanoids

if you’re following a tutorial why don’t you just follow it?

Anyway it looks like you can create a simple constant like “YAdjustment” for each enemy. then when positing the enemy just add the constant to the y position.

Or maybe using the Pivot tool in your Model tab to edit the Pivot of the (non humanoid) humanoid root part down 3 studs (or whatever) will help.