GetChildren not working

Currently, I am working on a system that will detect if certain parts are destroyed and ensure that if they are not recreated, for the player to be kicked. I still worry about exploiters even with Byfron rolling out so I want to make sure my game is protected.

Currently, I have a script that creates a part. When this part is created I am also priting a statement so I know that the code has run and the part has been made and the parent is the character, however my secondary script with the check will not actually get it when using GetChildren or FindFirstChild.

Both scripts are server side and the script bellow is the one that checks for the part to exist and even when it does exist both in my explorer and the script that creates a part sends it out, it still never appears

local players = game:GetService("Players")

function exploitDetection(child,parent,player)
	local detection = child
	wait(5)
	local wow = parent:FindFirstChild(detection)
	print(detection)
	print(wow)
	print(parent:GetChildren())
	if parent:FindFirstChild(detection) == nil then
		player:Kick("Exploit Detected")
	end	
end
players.PlayerAdded:Connect(function(player)
	
	local character = player.Character or player.CharacterAdded:Wait()
	
	character.ChildRemoved:Connect(function(child)
		if child.Name == "Hurtbox" then
			local check = coroutine.create(exploitDetection)
			coroutine.resume(check,child.Name,character,player)
        end
    end)
end

You are not using FindFirstChild right.
As shown by Instance | Roblox Creator Documentation
You should use FindFirstChild("My Part Name") or FindFirstChild(detection.Name) where .Name return a string (the object name)

They passed the name of the object. They used it correctly.

He indeed did, I got confused by the code. My fault here.

1 Like

Nothing appears to be wrong with your code, but one thing I will recommend, or suggest rather: change this to a CharacterAdded event and connecting a function to it instead of getting the character like this. This will ensure the code runs with every new character, because if they die, this will not run with the new character.

It can simply be changed to this:

player.CharacterAdded:Connect(function(character)	
	character.ChildRemoved:Connect(function(child)
		if child.Name == "Hurtbox" then
			local check = coroutine.create(exploitDetection)
			coroutine.resume(check,child.Name,character,player)
		end
	end)
end)

I did some tests and came to the conclusion that you are probably running this script on the server side, while deleting the " Hurtbox" part on the client side, which doesn’t trigger the server-side.

Thanks for everyone’s help. I believe the problem was that the character passed in was actually still referencing the old character that was getting deleted, or something similar to that.
I ended up fixing this by finding the character again in my coroutine after the 5 seconds have passed and then getting the children of the new character

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