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

Only works in studio?

In the serverscriptstorage I have a script that gets a custom player model I made and turns you into the model it works fine in studio but not online any reason why? also I am getting this output without Player.CharacterAdded the script does not work so I do not understand this. output vvv

01:30:43.437 - Maximum event re-entrancy depth exceeded for Player.CharacterAdded 01:30:43.439 - While entering function defined in script
--Here is the script
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local ControllerService = game:GetService('ControllerService')
for key, value in pairs(ControllerService:GetChildren()) do 
    if value:IsA('HumanoidController') then 
        value:Destroy()
    end
end
local newCharacter = game.ReplicatedStorage.newPlayer:Clone()
local SpawnLocation = game.Workspace.SpawnLocation
newCharacter.Parent = workspace
newCharacter.Name = player.Name
newCharacter:MoveTo(SpawnLocation.Position)
player.Character = newCharacter
player.CanLoadCharacterAppearance = nil
local Humanoid = Instance.new("Humanoid", newCharacter)
newCharacter.Archivable = false
    end)
end)

Thanks ~KIHeros

1 answer

✓ Accepted answer

Please watch your tabbing. Tabbed code is much easier to read.

Here are the problems with your script:

  1. You connected a 'CharacterAdded' event to a function that adds a Character, which will loop until maximum event re-entrancy depth has been exceeded, as it says in the error. So, you will have to add a debounce.

  2. You are setting 'player.CanLoadCharacterAppearance = nil' after the Character has already been loaded, so it will not work. You have to move it up.

  3. You should use :MakeJoints method of the new character's model so you don't die when spawned

  4. Your old character will not be removed, so you have to remove it after you set Character property of the player to the new character

Here is the fixed script:

debounce = false
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		if not debounce then
			debounce = true
			
			player.CanLoadCharacterAppearance = false
			
			local oldChar
			while not oldChar do
				wait()
				oldChar = workspace:FindFirstChild(player.Name)
			end
			
			local ControllerService = game:GetService('ControllerService')
			for key, value in pairs(ControllerService:GetChildren()) do 
			    if value:IsA('HumanoidController') then 
			        value:Destroy()
			    end
			end
			
			local newCharacter = game.ReplicatedStorage.newPlayer:Clone()
			local SpawnLocation = game.Workspace.SpawnLocation
			
			newCharacter.Parent = workspace
			newCharacter.Name = player.Name
			newCharacter:MakeJoints()
			newCharacter:MoveTo(SpawnLocation.Position)
			
			player.Character = newCharacter
			local Humanoid = Instance.new("Humanoid", newCharacter)
			newCharacter.Archivable = false
			
			oldChar:Destroy()
			debounce = false
		end
    end)
end)

Hope this helped.

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