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.
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
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.
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.
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
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