Humanoid:Move() not working apparently

So I have this pig and I want to make it move so I tried using humanoid:Move() and it wasn’t working and there were no errors in the output, what’s happenings

code :

local function wander()
	local randX = math.random(-50,50)
	local randZ = math.random(-50,50)
	humanoid:Move(Vector3.new(randX,0,randZ))
end

while true do wait(1)
	wander()
end

You’re using :MoveTo, which isn’t :Move.

That code doesn’t help much though. Can you provide a reproduction model or place? There are a handful of reasons it wouldn’t move. Not short of some part of it being anchored.

Yeah I checked if the part was anchored and sadly it wasnt because I was hoping it would be,

also reproduction model what do you mean by that?

edit: @MrNicNac changed it to Move and it still isnt budging

Well because the code doesn’t seem to be the actual issue, I’m asking if you can provide a small reproduction place file or model file because posting working code doesn’t tell us anything about the actual setup going on.

Wel what do you think it could be though, I cant really give a place file because its a game im working on

Then we can’t help you without speculation. At least, I’m not going to. Too many speculative problems that would just be us all shooting in the dark.

We can solve the issue much faster if you can provide reproductions. I’m not asking for your entire game. It can just be a model file with the script that doesn’t work no matter which map it’s in.

I just tested your code with this

local humanoid = script.Parent.Humanoid

local function wander()
	local randX = math.random(-50,50)
	local randZ = math.random(-50,50)
	humanoid:Move(Vector3.new(randX,0,randZ))
end

while true do wait(1)
	wander()
end

image

And it works just fine. So the code has 0 issues.

1 Like

Wow thanks for testing it for me, but im still not sure whats going on well, I have the code inside of an OOP constructor I guess

local animal = {}
animal.__index = animal

function animal.new(object)
	local newAnimal = {}
	setmetatable(newAnimal, animal)
	
	newAnimal.object = object
	
	return newAnimal
end

function animal:Wander()
	local animal = self.object
	local humanoid = animal:WaitForChild("Humanoid")
	local humanoidRootPart = animal:WaitForChild("HumanoidRootPart")
	
	local oldWalkSpeed = humanoid.WalkSpeed
	local oldHealth = humanoid.Health
	
	local function wander()
		local randX = math.random(-50,50)
		local randZ = math.random(-50,50)
		humanoid:Move(Vector3.new(randX,0,randZ))
	end
	
	while true do wait(1)
		wander()
	end
end


return animal

I still can’t help you much with nothing but guesses. Have you verified the loop is running using print-debugging (literally, placing prints in places to check if the code runs there)?

Short of that, this is as far as I can help you since you’re unwilling to make a reproduction model.

Yeah I put prints to make sure the code was working multiples times to check that I wasnt going crazy and code is actually printing

edit : GOT IT WORKING LOL

the problem was that in my server script i was cloning the object but not referring to the cloned one

local function placeRandomly(obj,pos)
		local newObj = obj:Clone()
		newObj.Parent = workspace
		newObj:SetPrimaryPartCFrame(pos)
		print("Spawned "..obj.Name)
		for _, species in pairs(animals) do
			if obj.Name == species.Name then
				local dwiddleAnimal = animal.new(newObj)
				dwiddleAnimal:Wander()
			end
		end
	end