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

Output says Humanoid not a valid member of script please help!!!!?

local thum = script.Parent.Humanoid
local torso = script.Parent.Torso
local FollowingLength = 20
function FindAndFollow(pos)
	local people = {}
	local moveTo
	for i,v in pairs(workspace:GetChildren())do
		if v:IsA("Model") and v:FindFirstChild("Humanoid")then
			if game.Players:GetPlayerFromCharacter(v)~= nil then
				table.insert(people,v)
				
			end
		end
	end
	for i,v in pairs(people) do
		local pos = v.Torso.Position
		local mag = (pos - pos2). magnitude
		
		if mag <= FollowingLength then
			moveTo = v
			
		end
	end
	if moveTo ~= nil then
		return moveTo
	end
end




while game:service("RunService").RenderStepped:wait() do
	if thum.Health > 1 then
		local f = FindAndFollow(torso.Position)
		if f ~= nil then
			thum:MoveTo(f.Position)
		end
	end
end

2 comments

0

Can you tell us where this script is located?

0

it's game:GetService () not game:service.

2 answers

Hi. There are two things when looking at your code that may be causing you problems. The first part is in line 08. When you have

if v:IsA("Model") and v:FindFirstChild("Humanoid")then

What might be happening is that the Humanoid as not spawned in by the time you are running the function. Instead, try and use WaitForChild(). What that does is it will wait until it see's whichever child you have specified. If it cannot find it within 5 seconds then it will move along.

Your final code for that line should look like this.

if v:IsA("Model") and v:WaitForChild("Humanoid")then

The next part is on line 32 when you have

while game:service("RunService").RenderStepped:wait() do

The error here is that you put game:service. It's actually supposed to be game:GetService. So the final code for that line should be

while game:GetService("RunService").RenderStepped:wait() do

I hope this helped!

3 comments

0

Thank you I will try and see if this helped.

0

It says there is still no humanoid also, there is a bad argument on line 20. Do you know why?

0

Hmm.. What are you trying to do with the variable "MoveTo" on line 20? It could be because you are trying to set the variable to an object in this case "v". Which it doesn't like. Are you trying to have the object in the variable? The name? Position? etc.

Try switching

if v:IsA("Model") and v:FindFirstChild("Humanoid")then

to

if game:GetService("Players"):FindFirstChild(v.Name) then

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