Changing the Players Character

I am experiencing difficulties changing the player’s character to a different character model. Typically, to achieve this, you name the desired character rig “StarterCharacter” and parent it to the StarterPlayer folder in Studio. Then whenever a player respawns or a new player joins, they automatically spawn with the designated character model. However, my requirement is different: I want only the player who clicks a specific GUI button to reload with the new character model, while all other players in the server should retain their default characters regardless of respawns or reloads.

Here are the scripts I found –

Local script:

-- This Script is Parented to the GUI button

script.Parent.MouseButton1Click:Connect(function()
	task.wait(3)
	local plr = game.Players.LocalPlayer
	local camera = workspace.CurrentCamera
	local rig = game.Workspace.VP.OutfitPlace.FitFolder.Bunny
			
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = rig.HumanoidRootPart 

	game.ReplicatedStorage.ChangeCharacter:FireServer(plr)
end)

Server Script:

-- This Script is Parented to the ServerScriptService
local dontrepeat

local function onChangeCharacter(plr)
	local char = plr.Character
	local rig = game.Workspace.VP.OutfitPlace.FitFolder.Bunny

	-- Check if rig's HumanoidRootPart already has "DontRepeat"
	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

game.ReplicatedStorage.ChangeCharacter.OnServerEvent:Connect(onChangeCharacter)

The intended functionality of these scripts is as follows: when a player clicks the GUI button, the local script communicates with the server script to identify the player who clicked the button. The server script then assigns the specified rig, called “Bunny”, to this player and destroys their previous character. However, when this transition occurs, I encounter several issues.

This is an example of what I want to happen after the Players character is changed:

  1. The player moves well and correctly animates

  2. The camera angle is correctly positioned so that if you zoom in you zoom into the character’s head

  3. When the player zooms in the player’s Character and accessory fade out becoming transparent

  4. When in shift lock or fully zoomed in the character will always face the way the player’s camera is facing

This is an example of what does happen after the player clicks the GUI and the players character is changed

  1. The player does not move or animate correctly

  2. The camera angle is not positioned correctly and when I zoom in it goes to the torso (It should be zooming into the head)

  3. When zoomed in all the way the character and the accessories are still visible and obstruct the view

  4. When in shift lock or fully zoomed in the character does not face the direction of the player’s camera

Requirements:

  1. Exclusivity: Only players who click the GUI button should have the “Bunny” character. Additionally, these players should respawn with the “Bunny” character upon death or reload, while all other players should retain their default characters.

  2. Functional Fixes: The “Bunny” character should be fixed so that it moves, animates, and zooms correctly, aligning with the desired behavior described above.

I would appreciate any assistance in resolving these issues :blush:

1 Like

Seems like since you’re doing this on request and not automatically whenever a player joins, you might also have to add the movement animations manually alongside the character model. The weird zoom could be the result of the main part of the model being set improperly or something along those lines. For the accessories going invisible perhaps that’s also something you’d have to manually implement.

So for the animations you should keep the “Animator” script which is a localscript disabled until you set the rig to the players character and parent it to workspace. For the Camera issue, you have to do that via client. Something like a listener for when the character property on the player changes and set workspace.CurrentCamera.CameraSubject to the Humanoid of the new character. Hope this works, I am just assuming these are what’s wrong with it.

2 Likes

Thank you so much, this was such a help to me. All I had to do was add a simple listener script to the local script and play the animation script manually.

game.Players.LocalPlayer:GetPropertyChangedSignal("Character"):Connect(function()
    local character = game.Players.LocalPlayer.Character
    if character then
        -- Set the camera to follow the new character
        local camera = workspace.CurrentCamera
        camera.CameraType = Enum.CameraType.Custom
        camera.CameraSubject = character:FindFirstChild("Humanoid")

        -- Enable the local animation script
        local animationScript = character:FindFirstChild("AnimationScript")
        if animationScript then
            animationScript.Disabled = false
        end
    end
end)

Glad I was able to help fix your script. Keep the good work up.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.