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

Infinite yield possible on 'testDummy:WaitForChild("Humanoid")?

It keeps says this error message or it would say Humanoid is not a valid member of "testDummy"

My testDummy is in a folder in serverStorage called AiFolder

This is called in a different script.

The testDummy has everything a character has

If you need any more information, PLEASE tell me. I have been working on this problem for a good 3 days now. It is starting to get annoying.

local enemy = {}

function enemy.AI(enemyModelName, enemySpawningPlatformName, yOffSet)
	-- Detects if the AI is in folder! Printed output if true
	-- If the AI is not showing, then there is no created AI in folder
	local AiFolder = game.ServerStorage.AiModels
	for i, v in pairs(AiFolder:GetChildren()) do
		if tostring(enemyModelName) == tostring(v) then
			-- Prints if the AI is in folder
			print("Found model "..tostring(v))
		end
	end
	
	-- Detects if the spawning platform is in the spawning folder
	-- If not then it would do nothing!
	local spawningFolder = game.Workspace.Map.AiSpawningPlatform
	local spawningPlatform = spawningFolder[enemySpawningPlatformName]
	for i, v in pairs(spawningFolder:GetChildren()) do
		if tostring(spawningPlatform) == v.AiSpawningName.Value then
			-- Prints if spawning platform is in folder!
			print("Spawning platform "..tostring(v).." is in folder!")
		end
	end
	
	-- Spawns the AI at the spawning Platform
	-- The Ai comes from the Folder
	local function spawnEnemy()
		-- Positions of the spawning platforms
		local xPosition = spawningPlatform.Position.X
		local yPosition = spawningPlatform.Position.Y
		local zPosition = spawningPlatform.Position.Z
		
		local AiSpawnModel = game.ServerStorage.AiModels[tostring(enemyModelName)]:Clone()
		AiSpawnModel.Parent = game.Workspace
		
		-- Getting the specific AI
		--local AiModel = game.ServerStorage.AiModels[enemyModelName]
		--local AiSpawnModel = AiModel:Clone()
		--AiSpawnModel.Humanoid.Health = 100
		--AiSpawnModel.HumanoidRootPart.Position = Vector3.new(xPosition, yPosition + yOffSet, zPosition)
		--AiSpawnModel.Parent = game.Workspace.Map.Enemy[tostring(spawningPlatform.islandType.Value)]
	end
	spawn(spawnEnemy)
	wait(1)
	
	local AiObjectModel = game.Workspace[tostring(enemyModelName)]
	
	-- This function will detect when the enemy is dead
	while true do
		wait()
		AiObjectModel:WaitForChild("Humanoid").Died:Connect(function()
			AiObjectModel:Destroy()
			spawn(spawnEnemy)
		end)
	end
end

return enemy

4 comments

0

The big comments is what I had earlier, I was just seeing if it was something with the :Clone() funciton

0

do you really have "Humanoid" inside testDummy?

0

Yes It has everything a character has, I had to double check.

0

I can see the humanoid inside of testDummy but the WaitForChild() function would not I guess detect it?

2 answers

✓ Accepted answer

It's not an error. It's just a warning that IF the object you are waiting doesn't exist then the script will not continue. It only shows up when it takes some time for the object to show.

3 comments

0

I have tried to use it without the WaitForChild() function then it would output an error says Humanoid not a valid member of testDummy

0

Scripts typically load before and run faster than sibling objects. This ís why it's necessary to use :WaitForChild(). The message ís not an error.

0

I have found a solution.

This is the code that activates the modules script

local enemy = require(game.ServerScriptService.EnemyAIModule)

enemy.AI("testDummy", "spawnTestDummy", 2.5)

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