Data is not a valid member of Humanoid "GhostHumanoid"

So, given the title, Data is not a valid member of Humanoid “GhostHumanoid”. I do know the issue and that it is my script is still looking for the model after it is destroyed, but I am kind of loss in how I could fix this error as it just fills up my output logs. Any help with trying to figure out a method of not having this appear would be greatly appreciated!

	if hitPart ~= nil and values.capturable.Value == false then
		hitPart.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("GhostHumanoid")
			GHumanoid = hit.Parent:FindFirstChild("GhostHumanoid")
			if humanoid then
				touchingHumanoids[humanoid] = true
			end
		end)
		hitPart.TouchEnded:Connect(function(hit)
			GHumanoid = nil
			table.clear(touchingHumanoids)
		end)
		while true do
			if GHumanoid then
				if GHumanoid.Data.Config.trappable.Value == true then
					if hitPart ~= nil and GHumanoid.Health >= 35 then
						for humanoid in pairs(touchingHumanoids) do
							humanoid:TakeDamage(DAMAGE)
						end
					end
				else
					if hitPart ~= nil and GHumanoid.Health >= 0 then
						for humanoid in pairs(touchingHumanoids) do
							humanoid:TakeDamage(DAMAGE)
						end
					end
				end
				task.wait(INTERVAL)
			else
				break
			end
		end
	end

Just add some checks… Here:

if hitPart ~= nil and values.capturable.Value == false then
	hitPart.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("GhostHumanoid")
		GHumanoid = hit.Parent:FindFirstChild("GhostHumanoid")
		if humanoid then
			touchingHumanoids[humanoid] = true
		end
	end)
	hitPart.TouchEnded:Connect(function(hit)
		GHumanoid = nil
		table.clear(touchingHumanoids)
	end)
	while true do
		if GHumanoid then
			local Data = GHumanoid:FindFirstChild("Data")
			if not Data then continue end
			
			local Config = Data:FindFirstChild("Config")
			if not Config then continue end
			
			local trappable = Config:FindFirstChild("trappable")
			if not trappable then continue end
			
			if trappable.Value == true then
				if hitPart ~= nil and GHumanoid.Health >= 35 then
					for humanoid in pairs(touchingHumanoids) do
						humanoid:TakeDamage(DAMAGE)
					end
				end
			else
				if hitPart ~= nil and GHumanoid.Health >= 0 then
					for humanoid in pairs(touchingHumanoids) do
						humanoid:TakeDamage(DAMAGE)
					end
				end
			end
			task.wait(INTERVAL)
		else
			break
		end
	end
end

Those just cause the game to freeze, would it be wise to throw an else statement into those and if else it breaks the loop?

Why do you think it makes the game freeze?

1 Like

I don’t think, I know they did. I had to restart my studio.

Maybe because its the loop you have on without a wait :skull:
Try this:

while task.wait() do

instead of:

1 Like

I have a wait in that loop.

task.wait(INTERVAL)

If the FindFirstChild doesn’t find anything it will skip the code. Maybe replace my continue with break

1 Like

Ah wait, it worked when I replaced the true with the wait, feel dumb about that. Appreciate all the help.

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