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

Making a player use a custom character? UNANSWERED

Goulstem's method crashes the server


Let's just say there's a model called Bob in the lighting and it has a armor welded to its torso.

game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character)
local bob = game.Lighting.Bob

Now I wanted the player to spawn as Bob so do I clone Bob and move his components to the player and delete the player's limbs? Help!

2 answers

Destroy the character when it spawns, set the character property of the Player to that model.

The model must have the appropriate children for it to work - Head, and Humanoid. If you want it to be able to walk and stuff then Clone the Animate localscript and place it into the new character, but make sure you have Arms and Legs in your model

Also, Lighting isn't meant to be used for storage, use ServerStorage.

Example;

local model = game.ServerStorage.Bob --Model

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		local anim = char:WaitForChild('Animate'):Clone()
		char:Destroy()
		local newChar = model:Clone()
		anim.Parent = newChar
		newChar.Parent = workspace
		plr.Character = newChar
	end)
end)

2 comments

0

woops, the server crashes as well,but on the test version a message pops out and shows this "Error on visit: The Parent property of Player is locked, current parent: NULL, new parent Workspace"

2

@SomeoneYetUnnoticed Play around with it. After all, it's an example script. One thing I will say though, try and move line 6 after line 10.

I'd like to know more about this too. I've experimented with different possibilities without success. I have changed the nested anonymous functions to just one anonymous function. That seems to get rid of the infinite recursing error thrown by the code @Goulstem posted.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:wait()
	-- magic goes here to use a different model as the character
end)

Can anyone provide some code that works? Thanks!

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