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

Why is my character not being sent to replicatedstorage?

I really can't find an explanation to this, I have been using PlayerAdded for a long time and suddenly it stops working.

game.Players.PlayerAdded:Connect(function(player)
	if player.Character then print("What?") player.Character.Parent = game.ReplicatedStorage end
	player.CharacterAdded:connect(function(char)
		print("-_-")
		char.Parent = game.ReplicatedStorage
		print("LOL")
	end)
end)

The player should get sent to replicatedstorage, but that doesnt happens and it stays on workspace. Even the print output "-_-" and "LOL" appears but the character parent doesn't change. No error messages appear.

I also tried with game.Lighting and it didnt work too, :Destroy() worked but I want to use the character later.

3 comments

0

sending a character to replicated storage? honestly I've never heard of that before nor do I have a guess on the usage of it... but maybe try to send a clone of it instead?

0

What exactly is the purpose of it? I'm honestly just curious

0

I would like to make a menu where the character is safe, without need to set the scripts not to mess with a character when he is on the menu.

1 answer

✓ Accepted answer

I have no clue why you want to do this but.. The issue is that you have not allowed the player to finish spawning into the game ie become a child of the workspace so attempting to change the parent before this will cause an warning.

Just wait a bit for the player to spawn into the game

simple solution

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(char)
	wait(1) -- wait for the player to be parented into the game
	char.Parent = game.ReplicatedStorage	
    end)
end)

A more complex event based soluction

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(char)
		-- gets a script signal for when the character model parent is changed
		char:GetPropertyChangedSignal('Parent'):Connect(function()
			-- on parent change check if the model is in the workspace
			if char:IsDescendantOf(workspace) then
				wait() -- final wait or this will cause a warning before setting the parent
				char.Parent = game.ReplicatedStorage	
			end		
		end)
    end)
end)

I hope this helps. Please comment if you have any other questions about this code.

1 comment

0

Thanks, I will just change the char:GetPropertyChangedSignal('Parent'):Connect() to char:GetPropertyChangedSignal('Parent'):Wait(), as I want him to get to workspace later and this line would interfere with my other codes.

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