Issue with parenting player/character model to a folder

How do I parent a player to a folder instead of having them spawn in the workspace? I want to parent them to a folder so it is easier to check all character models for a table (like ignorelists in raycasts), but when I do so the player will refuse to spawn at all.

Unfortunately, you cannot put player objects in folders.

Describe what you mean by “easier to check all character models for a table”, I could help you find an alternative solution for that.

basically, I’m trying to get my raycast to stop detecting humanoidrootparts, but if i include that in the if-then statement for the OnHit function, it won’t try to hit anything else it’ll just ignore everything else (eg "if …hit.Name ~= “HumanoidRootPart”)

so that’s why i wanted to set it up for the ignorelist for the raycast itself instead so it can ignore the rootpart and hit torso instead, but there’s no easy way to find all rootparts for all players, only an easy way for pedestrians since there’s a folder for that

Here is a simple script to find every HumanoidRootPart

local humanoidrootparts = {}

for _, part in pairs(game.Workspace:GetDescendants()) do
     if part.Name == "HumanoidRootPart" then
          table.insert(humanoidrootparts,part)
     end
     -- if you have a lot of parts it's ideal to put a delay here to prevent Studio from crashing
end
2 Likes

Not sure if you ever solved this in the 3 years since this post, but I’m reviving this with a solution for yourself and anybody else who comes across this thread in search of answers like I did.

In Workspace, create your folder. Mine is called “PlayerCharacters” in this example.

In Replicated Storage, create a new Remote Event and name it something identifiable. In my case, I went with “SendCharacter” as that’s somewhat the reason I’m using it…despite not actually sending the character.

Anyway, next in a client script, create a function that connects to the local player’s CharacterAdded event like so:

local player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sendCharacterRemote = ReplicatedStorage.SendCharacter

--{ON CHARACTER ADDED EVENT}--
local function onCharacterAdded(character: Model)
	sendCharacterRemote:FireServer()
    --Add any other code you need to execute onCharacterAdded here.
end

--{{INITIALIZE CHARACTER ON ADDED}}--
local function initialize()
	player.CharacterAdded:Connect(onCharacterAdded)

	if player.Character then
		onCharacterAdded(player.Character)
	end
end

initialize()

After that, create a new script in the ServerScriptService and name it something like “ReParent” with the RunContext set to “Server.” This is where the actual reparenting happens as you’ll need this to replicate on every client. Paste this in the script and swap the remote name and folder names with your own.

--[[
	ReParent - This script handles the reparenting of Players into a custom workspace folder. It is activated via remoteEvent.
--]]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local sendCharacterRemote = ReplicatedStorage.SendCharacter

local function onSendCharacterEvent(player: Player)
	-- Make sure the player has a character
	local character = player.Character
	if not character then
		return
	end
	player.Character.Parent = workspace.PlayerCharacters
end

sendCharacterRemote.OnServerEvent:Connect(onSendCharacterEvent)

That’s it. You’re done. If you want to exclude this folder from a raycast, just add it to the filter of your raycast params.

RaycastParams:AddToFilter(workspace.PlayerCharacters)