Character change In-Game

Hello, Developers!

I’m trying to change players character when is In-Game. I tried looking on devforum but i couldn’t find anything that could help me.

I tried changing players character with 2 script but they didnt work.

Error: Remote Event won’t fire

Local Script:

local KillerEvent = game.ReplicatedStorage.KillerEvent
local Killers = game.ReplicatedStorage.Killers
local Changed = script.Change

while wait(.1) do
	if script.Parent.Main.Killer.Value == true and Changed.Value == false then
	Changed.Value = true
	print("Fired")
	local plr = game.Players.LocalPlayer
	local ChosenKiller = plr.Equipped.Killers
	local model = ChosenKiller.Value
	assert(model, "model does not exist for this location!")

	KillerEvent:FireServer(model.Name)
	end
end

Main Script:

local function respawnPlayer(plr, modelName)
	local model = game.ReplicatedStorage.Killers:FindFirstChild(modelName)
	print("Model from server is", model)

	local oldModel = plr.Character
	local newModel = model:Clone()
	
	print(newModel)
	local oldCFrame = oldModel:GetPrimaryPartCFrame()

	plr.Character = newModel
	newModel.Parent = workspace -- [1] this follows current character loading behavior
	newModel:SetPrimaryPartCFrame(oldCFrame)
	oldModel:Destroy()
end

game.ReplicatedStorage.KillerEvent.OnServerEvent:Connect(respawnPlayer)

Can you explain what you need? I dont know what change character in game means

Change players character when the game starts, so all the players gets parented to an folder called survivors then 1 players get chosen as a killer and i want the killer to get the character that they selected while being in lobby

If someone can help me it would be very appreciated! :slight_smile:

I can help you!

So, in BaseAdmin, I created this mech command that replaces your character with a mech.

Here’s the code for that:

t.mech = {function(Player, plr, rig)
	local plrs = getPlayerRun(Player, plr)
	for i=1,#plrs do
		if rig == 'r6' then
			plrs[i].Character.Humanoid.RigType=Enum.HumanoidRigType.R6
		end
		if rig == 'r15' then
			plrs[i].Character.Humanoid.RigType=Enum.HumanoidRigType.R15
		end
		local mechclone
		if plrs[i].Character.Humanoid.RigType==Enum.HumanoidRigType.R15 then
			mechclone = script.Assets["Mech R15"]:Clone()
		else
			mechclone = script.Assets["Mech R6"]:Clone()
		end
		local pos = plrs[i].Character.PrimaryPart.Position
		plrs[i].Character:Destroy()
		mechclone.Name=plrs[i].Name
		mechclone.Humanoid.DisplayName = mechclone.Name.."'s mech"
		plrs[i].Character=mechclone
		mechclone.Parent=workspace
		mechclone:MoveTo(pos)
	end
end, "Turns the target player(s) into a mech", '<plr> <optionalRigType>', 3}

To replace the character, you must first destroy it, and then set the property. I’m not sure if the new character has to be in workspace or not.

Also, in some cases, you must manually set the CameraSubject of the Camera from a LocalScript. I didn’t have to do this here.

Yes, you can replace MoveTo with SetPrimaryPartCFrame, it’s way better. The only reason I am using MoveTo is because the mech is larger than the normal character, and SetPrimaryPartCFrame would cause it to clip through the floor.

Can you explain it better? I asked how to change the players character only, and i got an mech script? Where i should put it? And how it can be fired when the game starts?

Alright, I can try to explain it. The mech command does what you need it to do, change your character. First, it will detect the rig type, then select the correct rig.

Then, it will get the character’s position. It will place the cloned new character in that position. Then, it will :Destroy() the old character. After that, Player.Character is set to the new character, and the new character is parented to workspace. Only then can it be moved into the old character’s spot.

I would not use BaseAdmin if i was you. After watching the code there are multiples moment where the script will try to teleport a users in places, exept for the “intended one” in the main script, there also some local script that do it. I looked at it quickly so i may be wrong but from what ive seen the script is half legitimate

But I created BaseAdmin.

The teleport commands are just “fun commands” and they are intended.

There is also a teleportation utility that will teleport players to a lobby to update the game.

But thanks for being careful.

1 Like

No sir, I asked how to use the function you send me? I don’t even know where to put it in the script, how to fire the function etc.

Anyways, I figured it out and made the script myself!