Parent not changing while it's supposed to

Hello! I’m making a script that teleports you, and it places the part you teleported to in a seperate folder and puts it back in the normal folder later on.

Script part:

if #parts:GetChildren() <= 0 then
				print("Parts Empty")
				for i, v in pairs(workspace.TPPlayersRed:GetChildren()) do
					v.Parent = workspace.RedTeam
				end
				for i, v in pairs(workspace.TPPartsRed:GetChildren()) do
					v.Parent = workspace.RedParts
				end
				return
			end

Yet it does not change the parent, please yelp, thanks.

1 Like

is there any errors? it would help alot!

3 Likes

No, it just doesn’t do anything. No errors.

1 Like

Is there anyone else that can help?

I need this fixed by today

1 Like

i dont think you can change a parts parent to a folder because i have tried it before and it hasnt worked. (atleast for me)

1 Like

Yet I can change the parent of a player character to a folder

1 Like

try debugging it

if #parts:GetChildren() <= 0 then
				print("Parts Empty")
				for i, v in pairs(workspace.TPPlayersRed:GetChildren()) do
					v.Parent = workspace.RedTeam
				end
				for i, v in pairs(workspace.TPPartsRed:GetChildren()) do
                                        print("yes this runs so we change the parent woo")
					v.Parent = workspace.RedParts
				end
				return
			end

see if anything prints

1 Like

I think I’m a bit confused, what exactly is this script supposed to do? Why are you checking if the “Parts are Empty”?

1 Like

It does not print anything. Not even the first line after the ‘if’

1 Like

I don’t think it matters. It’s to stop the code, put all the stuff back and it will be ready to loop again when I need it to

1 Like

so the parts are not empty then and #parts:GetChildren is more than 0

1 Like

<= means less or equal to.

Don’t mind this text it’s for the minimun character thingy

1 Like

Right, I think what they meant was that the #parts must not be less or equal to 0, because your code doesn’t seem to be working at all.

1 Like

So for what you just said, you are saying I should use == instead of <=?

1 Like

I’m not fully sure, but I would maybe replace it with >= just to see if the that’s the problem. If that fixes it then at least you know that the problem is the number of parts, and not the actual code that changes the parent.

1 Like

thanks for telling me that. I know.

I said that you want it to be less or equal but it is actually MORE than 0.

1 Like

No. It’s 0. There is 1 player which I can see moving to another folder, then it checks if there are any still left in the original folder, if there is not, it takes what is in the teleported players folder and moves it back to the original folder, so it can be used again.

1 Like

It does nothing. It does not print anything.

1 Like

if it doesn’t print anything that means

if #parts:GetChildren() <= 0 then

this is false therefore only real explanation would be that #parts:GetChildren() <= 0 is false meaning #parts:GetChildren() is more than 0 to test this you should do

if #parts:GetChildren() <= 0 then
				print("Parts Empty")
				for i, v in pairs(workspace.TPPlayersRed:GetChildren()) do
					v.Parent = workspace.RedTeam
				end
				for i, v in pairs(workspace.TPPartsRed:GetChildren()) do
                    print("yes this runs so we change the parent woo")
					v.Parent = workspace.RedParts
				end
				return
    else print("more than 0")
end

2 Likes

So you just have to convert objects that are into the folder to a number value…

local Number = 0

for _, Childs in pairs(#parts:GetChildren())do
	Number += 1
end

if Number <= 0 then
	print("Parts Empty")
	for i, v in pairs(workspace.TPPlayersRed:GetChildren()) do
		v.Parent = workspace.RedTeam
	end
	for i, v in pairs(workspace.TPPartsRed:GetChildren()) do
		v.Parent = workspace.RedParts
	end
	return
end
2 Likes