Sheep NPC randomaly wandering around script not working!

  1. I want a sheep NPC randomaly wandering around

  2. My script doesn’t work!

  3. I tried fixing it and didn’t know how

Can anyone please help me?

local wanderTarget 
local wanderAngle 
local wanderConeSize = 6
local maxWanderAngle = 1

function getWanderTarget()	
	math.random(tick())
	wanderAngle = (math.random() - 0.5) * maxWanderAngle
	rotatedLookVector = CFrame.Angles(0, wanderAngle, 0) * script.Parent.Torso.CFrame.lookVector
	return (script.Parent.Torso.Position + wanderConeSize * rotatedLookVector)
end

while true do  	
	local ray = game.Workspace:FindPartOnRay(Ray.new(script.Parent.Torso.Position, script.Parent.Torso.CFrame.lookVector * 5.0), nil)
	if ray and script.Parent.Humanoid then
		script.Parent.Humanoid.Jump = true
	end     
	wanderTarget = getWanderTarget()	
	script.Parent.Humanoid:MoveTo(wanderTarget, script.Parent.Torso)
	wait(0.125)
end 

Well to me at first glance the script looks fine, is the sheep anchored?

2 Likes

No the sheep is perfectly fine, animations work aswell as animations scripts and MoveTo too

A nice short video clip about 8 to 10 seconds long would be very helpful so we can see exactly what’s wrong with your sheep NPC

This should work for you any issue reply to this and i can help you. :slight_smile:

local wanderTarget
local wanderAngle
local wanderConeSize = 6
local maxWanderAngle = 1

math.randomseed(tick())

function getWanderTarget()
wanderAngle = (math.random() - 0.5) * maxWanderAngle
local rotatedLookVector = (CFrame.Angles(0, wanderAngle, 0) * script.Parent.Torso.CFrame.LookVector).Unit
return (script.Parent.Torso.Position + wanderConeSize * rotatedLookVector)
end

while true do
local ray = game.Workspace:FindPartOnRay(Ray.new(script.Parent.Torso.Position, script.Parent.Torso.CFrame.LookVector * 5.0), nil)
if ray and script.Parent.Humanoid then
script.Parent.Humanoid.Jump = true
end
wanderTarget = getWanderTarget()
script.Parent.Humanoid:MoveTo(wanderTarget, script.Parent.Torso)
wait(0.125)
end

1 Like

Thanks for the reply, I managed to fix it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.