Parent of Character will not set

Hello, I have this sorting script in my games Workspace. It works fine most of the time, but sometimes it will throw and error saying “Something unexpectedly tried to set the parent of PLAYER to DESTINATION, setting PLAYER Parent to Workspace.”

I have tried to counter this by placing a script in the starter character folder, which will kick a player from the game if their avatar has fully loaded, and if not parented to my destination folder. This script works, but when the player rejoins the same server, it will always throw the same error for that player.

Here is the sorting script, I have tried adding a Spawn() function to give the game a moment to set the parent of the avatar. The error still happens.

bounce = true

while true do
	if not bounce then
		return
	end
	bounce = false
	if game:GetService("Workspace"):FindFirstChildWhichIsA("Model") and game:GetService("Workspace"):FindFirstChildWhichIsA("Model").Name ~= "Phoenix" then
		spawn(function()
			game:GetService("Workspace"):FindFirstChildWhichIsA("Model").Parent = game:GetService("Workspace"):FindFirstChild("Players")
		end)
	else
	wait()
	end
	bounce = true
	wait()
end
1 Like

I’m not sure if this is your issue or not, but you can use a connection to ChildAdded instead of a loop for that. It’ll only run the function when something new is added to the workspace, instead of over and over again.

Example:

workspace.ChildAdded:Connect(function(child)
    -- sorry for bad indenting, just using spaces since mobile
    if child:IsA("Model") and child.Name ~= "Phoenix" then
        child.Parent = workspace:FindFirstChild("Players")
    end
end

If you just want to move characters to the folder, you can get rid of the if statement altogether:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.Parent = workspace:FindFirstChild("Players")
    end)
end)
2 Likes

First code don’t seem to work at all, and the second code seems to work, but then the Model is immediately changed back to Workspace, and the character is killed. Once the character respawns, the camera is not attached.

This is why my current script is looped. I’m not sure why this is the outcome.

-- script
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		wait()
		chr.Parent = workspace:WaitForChild("players")
		RemoteEvent:FireClient(plr)
	end)
end)
-- local script
RemoteEvent.OnClientEvent:Connect(function()
	workspace.CurrentCamera.CameraSubject = game.Players.localplayer.Character:WaitForChild("HumanoidrootPart")
end)

this works fine for me, no character dying or the character being moved back to the workspace/camera removes attaching
just make sure you know how Remote events and functions work.

2 Likes

What you’re probably experiencing is interference from the backend. Roblox parents characters to the workspace, so running a parent function in parallel will interfere with that operation.

The whole warning message is literal. Unexpectedly, while one script was evaluating a statement to parent the model somewhere, another script launched the same operation at the same time. Said operation is then cancelled and the original operation continues.

Or I think that’s what’s happening.

This is working so far, thank you so much, I will come back here if I encounter another issue that I can’t handle.