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

Trying to use ":GetChildren()" on a model with a humanoid, getting error?

I'm trying to change a enemy npc's position when the time is at 21 hours (which i've done), I used a for loop, and when it gets to humanoid, it errors out. Can someone come to my aid with some help? I will include the code below:

local lighting = game.Lighting
local monster = workspace.Monster
local monsterSpawn = workspace.monsterSpawn.Position

while true do
	lighting:SetMinutesAfterMidnight(lighting:GetMinutesAfterMidnight() + 0.75) -- dont touch (well if u want u can)
	wait(0.001) -- change to whatever you want
	if lighting.ClockTime >= 21 then
		local parts = monster:GetChildren()
		for i, v in pairs(parts) do
			v.Position = Vector3.new(monsterSpawn.X, monsterSpawn.Y, monsterSpawn.Z)
		end
	end
end

Thanks to anyone who helps :)

1 comment

0

Not all children are parts. Use if v:IsA("BasePart") then

1 answer

✓ Accepted answer

That is because the Humanoid doesn't have a position. It's not a physical part of the player, but it holds properties such as the character's health. Instead of relocating all of the parts, why don't you just relocate the HumanoidRootPart? When you move the HumanoidRootPart, the rest of the body comes with it. Do this instead:

local lighting = game.Lighting
local monster = workspace.Monster
local monsterSpawn = workspace.monsterSpawn.Position

while true do
	lighting:SetMinutesAfterMidnight(lighting:GetMinutesAfterMidnight() + 0.75) -- dont touch (well if u want u can)
	wait(0.001) -- change to whatever you want
	if lighting.ClockTime >= 21 then
	monster.HumanoidRootPart.CFrame = CFrame.new(monsterSpawn.X, monsterSpawn.Y, monsterSpawn.Z)
        end
    end
end

1 comment

0

I tried to do that before,and it didn't work. However your one worked so congrats, have this "accept answer" button kind stranger.

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