Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

0
Just change the parent again. Note that there is a Players service in the game that is designed for your use. User#21908 42 — 5y
0
I don't know how to though MusicalDisplay 173 — 5y
3
It's char.Parent = workspace Am I missing something here? xPolarium 1388 — 5y
0
^ lol User#21908 42 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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.

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! MusicalDisplay 173 — 5y
0
k BlackOrange3343 2676 — 5y
Ad

Answer this question