I'm trying to make it so that when a player joins the game, the players character will be replaced with a model of mine. When it works, it should be able to do the same thing a normal player can, except the players image is different. (Pretty much a morph, but without any buttons and only a simple script)
This is a local script inside StarterGUI
wait(2) local plr = game.Players.LocalPlayer plr.Character:ClearAllChildren() game.Workspace.Chicken:MakeJoints() plr.Character = Workspace.Chicken
The script works to some extent. The players character is removed and the chicken seems to disappear but does not end up replacing the character and while the character is missing, I can't move. There's no outputs.
Thanks for helping. :)
Well, here are the problems. 1.) Character might not be loaded yet 2.) Character's body parts will fall off. 3.) Character is an Object value.
To wait for the character to load you must do this:
local character = plr.Character if not character or not character.Parent then character = plr.CharacterAdded:wait() end
To make the model stick you must make joints after everything else:
wait(2) local plr = game.Players.LocalPlayer plr.Character:ClearAllChildren() game.Workspace.Chicken:MakeJoints() plr.Character = Workspace.Chicken --Will Break apart wait(2) local plr = game.Players.LocalPlayer plr.Character:ClearAllChildren() plr.Character = Workspace.Chicken plr.Character:MakeJoints() --Will not
Characters can't change value:
game.Players.LocalPlayer.Character = "Hi" --Will error
The reason you cant move is because you don't have a 1.) Humanoid 2.) Animation Script 3.) Other vital movement stuff. This is all because you cleared the character's children.
If you want, you can use this script:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) player.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=13667373&placeId=0" --This is to look like me! Replace the "13667373" with a players ID. player:LoadCharacter() end) end)
Now just make a second roblox account and give it clothes to look like the chicken. Then you can replace "13667373" with the new accounts user ID.
If the chicken is not the same shape as a normal player, you can do this:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character.Torso.CFrame = CFrame.new(character.Torso.CFrame) * CFrame.Angles(5,0,0) --Or something character:MakeJoints() end) end)
Some of these scripts are just ideas.
Hope it helps!