Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Humanoid:MoveTo isn't following player?


	enemy = script.Parent.Parent.Parent.Parent.Parent.Parent -- Enemy
	hum = enemy.Humanoid -- Enemy Humanoid

	local function HealthFunc()
	
		script.Parent.Size = UDim2.new(0, hum.Health * 150/hum.MaxHealth, 0, 50) -- Scale Gui for the Bar
		script.Parent.Stat.Text = tostring(hum.Health).."/"..hum.MaxHealth -- Change the Text
	
		if hum.Health <= 0 then
		
			enemy:Destroy() -- Destroy Enemy if Health is 0 or less (If it's Dead)
		
		end
	
		if enemy.OV.Value ~= nil then
			hum:MoveTo(enemy.OV.Value.HumanoidRootPart.Position)
			hum.MoveToFinished:Wait()
			print(enemy.OV.Value.HumanoidRootPart.Position)
		end
	
	end

	HealthFunc() -- Reset GUI when Enemy Spawned

	hum.HealthChanged:Connect(HealthFunc) -- Trigger Function when Health of Enemy is 		Changed

The script tries to follow the player based on an object value.

if humanoid.Parent:FindFirstChild("OV") == nil then
		local objVal = Instance.new("ObjectValue")
		objVal.Name = "OV"
		objVal.Parent = humanoid.Parent
		objVal.Value = Player.Character
	else
		humanoid.Parent:FindFirstChild("OV").Value = Player.Character
	end
	humanoid:TakeDamage(Damage)

The object value is placed like this in the sword script and the enemy takes the position from the value of the object value.

No errors, it just doesn't work.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.