I want to create a game were the player switches to different custom characters but I am having difficulties switching the character for only one player.
an example of this is in dinosaur simulator, when a players dino grows up it appears that a new model is created and the players character is set to the new one.
I want to be able to do this but without killing the character. and I only want this to happen to one player individually. could someone please tell me how I can do this?
so I tried this inside playerscripts, and it didnt work, I then tried putting it in characterscripts, and while it did transfer control over to the new model, the camera remained fixed at were my old character was, is there a particular place I should be doing this at?
This problem feels like it was asked before so I hope my answer isnāt wrong, because I have currently no ways of testing this sorry.
You can use the :LoadCharacter() which reloads the character without killing him. And basically change the starter character then you playre:LoadCharacter().
When the player wants to change his character to something else, you would remove the first character, and replace it with the new one he chose that was probably stored somewhere in serverstorage or replicatedstorage. And of course the character has to be name StarterCharacter
ā¦,ā¦
Then when you player:LoadCharacter() the old character would reload without being killed and will have the new startercharacter
alright, so, i had an issue with this in the past, where i wanted character models to be swapped when a certain condition was in place (i.e. pressing a button to morph you into some other character). what i ended up doing is a bit finicky and definitely should be avoided, but unless someone comes up and advises a better way, hereās how i handled it.
game script:
local StarterPlayer = game:GetService("StarterPlayer")
local ServerStorage = game:GetService("ServerStorage") --place your new chara model in here
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent")
event.Name = "modelswapevent"
event.Parent = ReplicatedStorage
--leave bits out with oldmodel if you don't have StarterCharacter in StarterPlayer
event.OnServerEvent:Connect(function(charamodelname, player)
local oldmodel = StarterPlayer.StarterCharacter
local charamodel = ServerStorage:FindFirstChild(charamodelname)
newcharamodel = charamodel:Clone()
newcharamodel.Name = "StarterCharacter"
oldmodel.Parent = nil
newcharamodel.Parent = StarterPlayer
player:LoadCharacter()
newcharamodel:Destroy()
oldmodel.Parent = StarterPlayer
end)
local script:
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage.modelswapevent
-- insert code here or w/e
event:FireServer("modelname")
like i said, my method is likely a bit more complicated than it needs to be, but what it does is it quickly swaps out the starter character model for the one youād like to turn into temporarily ā for a SPLIT second.
This isnāt proper usage of StarterCharacter. You shouldnāt ever, really, be using StarterCharacter to switch out characters. It works but itās an unsupported hack.
Yeah I was deffintley sure that I was wrong! Sorry for the false information.
I wanted to try this out but studio isnāt available for me at the moment.
I unfortunately donāt and changing out characters is an issue Iāve been struggling with for well over a few years by now. My most recent thread regarding it was some months ago.
iāve also been struggling with it for years and the hacky/not good way iāve described earlier in this thread is the closest i have been able to accomplishing what i wanted. i hate using the method and would rather use something that isnāt as ābeat-around-the-bushā in nature.
I believe I found a solution to this ongoing problem. first here is what I did:
this is what you will need.
localscript:
wait(3)
local plr = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local rig = game.Workspace.TestRig
camera.CameraType = "Follow"
camera.CameraSubject = rig.HumanoidRootPart
script.Parent.RemoteEvent:FireServer()
normal script:
local dontrepeat
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
local char = plr.Character
local rig = game.Workspace.TestRig --the model you want to turn into--
if not rig.HumanoidRootPart:FindFirstChild("DontRepeat") then
plr.Character = rig
end
wait()
if not rig.HumanoidRootPart:FindFirstChild("DontRepeat") then
dontrepeat = Instance.new("Attachment")
dontrepeat.Name = "DontRepeat"
dontrepeat.Parent = rig.HumanoidRootPart
wait()
char:Destroy()
end
end)
setting the players character to a new rig does work however the camera does not change and will become locked in empty space, so I changed the camera to the new rig inside a localscript. and I set the players character from a normal script.
I put this folder inside startergui because the remote event wont work inside playerscripts.
and in doing so this folder gets cloned when the character is changed, so I used an attachement to tell the game that the new model has already been changed. so if it finds this attachment it wont fire again. I ran this once successfully but you can change it to your liking. I hope this helps anyone who is having trouble with changing custom characters.
When I used his solution, I was unable to get it to work. I do not remember where that folder was meant to go, but I do have another solution.
This one starts off with a local script under the starterGUI. For mine I made it so that when a button is clicked it changes your character, but all you need is a remote event to fire from the client. You can link this up to anything in your game.
function OnClick()
local model = putwhereveryourmodelishere
assert(model, "model does not exist for this location!")
game.ReplicatedStorage.respawnEvent:FireServer(model.Name) --Fires an event named "respawnEvent" to the server. Name this to your event.
end
script.Parent.MouseButton1Click:Connect(OnClick)
To get this to work all you need is to tell the server which character to change the player to.
Here is the server script that receives the message and changes the player. I put mine in server script server to keep it cleaner, but it should work anywhere.
replicatedstorage = game:GetService("ReplicatedStorage")
respawnEvent = replicatedstorage.respawnEvent
local dontrepeat
local function respawnPlayer(plr, modelName)
local model = replicatedstorage.Characters:FindFirstChild(modelName) -- I have all of my models in a folder named character, this is how the server finds them.
print("Model from client is", model) -- This print is unnecessary, but useful for debugging
if not plr.Character.HumanoidRootPart:FindFirstChild(modelName) then -- Check to see if the player is already a different model
local oldModel = plr.Character
local newModel = model:Clone()
local oldCFrame = oldModel:GetPrimaryPartCFrame()
plr.Character = newModel
newModel.Parent = workspace -- this follows current character loading behavior
newModel:SetPrimaryPartCFrame(oldCFrame)
oldModel:Destroy()
dontrepeat = Instance.new("Attachment")
dontrepeat.Name = modelName
dontrepeat.Parent = newModel.HumanoidRootPart
wait()
end
end
respawnEvent.OnServerEvent:Connect(respawnPlayer)
I believe this should work. If you have any issues or questions then hmu
local function change_character(player_)
local starter_player = game.StarterPlayer
-- delete OLD characters
local old_character = starter_player:FindFirstChild("StarterCharacter")
if old_character then
old_character:Destroy()
end
-- create and move the NEW character to the DESIRED location
local new_character_model = game.ReplicatedStorage["StarterCharacter_NEW_1"]:Clone()
new_character_model.Name = "StarterCharacter"
new_character_model.Parent = starter_player
-- restart the Ńharacter
player_:LoadCharacter(new_character_model)
-- !!! when used LoadCharacter(), the character will always be selected from "game.StarterPlayer."
end