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

Moving the Player's Character into and out of different folders?

Okay this may sound confusing but I will try to explain what I'm trying to do:

So what I have done is put the player's character inside of a folder called "Players" in workspace:

Keep in mind that this is in a SERVER script and I am able to get the player's name because I made a remote event. So this is inside of a function for a remote event :) (this isn't the problem)

local function FindCharacter(player)
	--GetCharacter--
	local char = player.Character
	local InGameFolder = game.Workspace.Players -- Folder that holds the Player's Character
	char.Parent = InGameFolder -- This puts their character inside of it.

end
		 
FindCharRE.OnServerEvent:Connect(FindCharacter)

NOW here is where I'm stuck at..

I don't know how to get them out. I tried clearing the folder with ClearAllChildren, but that obviously just deletes them.. How do I move their parent back to workspace?

I bet this is a pretty easy solution ,and I'm probably going to regret asking this question after hearing the solution but ykno.. I'm desperate.. :/

4 comments

0

Just change the parent again. Note that there is a Players service in the game that is designed for your use.

0

I don't know how to though

3

It's char.Parent = workspace Am I missing something here?

0

^ lol

1 answer

✓ Accepted answer

Hello! I'm BlackOrange and I'm gonna help you.

So, the solution is simple. First, let's think how YOU parented the character in the first place.

char.Parent = InGameFolder

Ok, from this line alone we can tell your commanding the character's parent to change to this InGameFolder Object. So how did you locate this object?

local InGameObject = game.Workspace.Players

Ok, so you made a variable for it.

Now let's think of the goal: "Get the character back to the workspace"

Hey, the word workspace sounds familiar. Let's take a look:

local InGameObject = game.Workspace.Players
char.Parent = InGameFolder

So the first block of code has "workspace" in it! I think you can use that! Wait I wanted to set the character back to workspace.

So:

char.Parent = game.Workspace

Hmm, this seems right...

So now test it out for yourself!

Good luck developer!

PS: Look at the other lines of code you have written, they can help you out.

2 comments

0

Thanks for your help man, it's appreciated! But I've been developing for about 4 years and I just had a little brain fart lol!

0

k

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