Character Changing Script Won't Work

I have been trying to make a ‘Milsim’ game about a non-specified war, even though it is clear.
I was making a script for it to change the character of a player based on their team.
I am unaware of any solutions, therefore I posted it here.
It is a LocalScript in StarterCharacterScripts. if you need any other details you can ask.
The outfits won’t load, and the player is in their default outfit too.

local RUS = game.ReplicatedStorage.StarterCharacter
local blueye = game.ReplicatedStorage.StarterCharacter2
local team1 = game.Teams.R
local betterteamaka2 = game.Teams.U
local players = game.Players.LocalPlayer
		local team = players.Team
		if team == team1 then
			local clone = RUS:Clone()
			clone.Parent = game.StarterPlayer
		elseif team == betterteamaka2 then
			local clone = blueye:Clone()
			clone.Name = "StarterCharacter"
			clone.Parent = game.StarterPlayer
		end
1 Like

You cannot use ServerStorage in a localscript
Use Replicated Storage

1 Like

Thank you, this worked but I still don’t get the character based off of my team.
It fixed the error only.

Ahh, I see, you need to weld and place the character’s item(s) on the player’s character, or entirely replace the players character and set the new character as the player’s character.

1 Like

How can you do that? Sorry, I know it’s stupid to ask.

You can either code it yourself or find a open source “Morph” module or script, to help you.

As for the setting the players character, you need to make sure the character has all the key components a character should have such as a humanoid and a Humanoidrootpart.

The solution here explains it very well: How to change custom character during game

1 Like

I tried to weld it to the player and it didn’t go well.

local RUS = game.ReplicatedStorage.StarterCharacter
local blueye = game.ReplicatedStorage.StarterCharacter2
local team1 = game.Teams.R
local betterteamaka2 = game.Teams.U
local players = game.Players.LocalPlayer

players.CharacterAdded:Connect(function(character)
	local team = players.Team
	local newCharacter
	if team == team1 then
		newCharacter = RUS:Clone()
	elseif team == betterteamaka2 then
		newCharacter = blueye:Clone()
	end

	if newCharacter then
		for _, item in ipairs(newCharacter:GetChildren()) do
			if item:IsA("BasePart") then
				local weld = Instance.new("Weld")
				weld.Part0 = character:FindFirstChild(item.Name)
				weld.Part1 = item
				weld.C0 = character:FindFirstChild(item.Name).CFrame:inverse() * item.CFrame
				weld.Parent = character:FindFirstChild(item.Name)
				item.Parent = character
			end
		end
	end
end)

The file for the video got corrupted it seems. If you want it:
robloxapp-20240804-1119063.wmv (1.6 MB)

I’m not quite sure if I understand what you mean, however you can use the Player.Character property to directly set a player’s character:

local NewCharacter: Model = characterreference:Clone() -- Clone the desired character (characterreference should be a path to the model you wish to set the player's character to)
local OldCFrame = Player.Character.PrimaryPart.CFrame -- Gets the current CFrame of the character for pivoting later on (Not required)
Player.Character:Destroy() -- Destroys the previous character
Player.Character = nil -- Sets the character to nil (This one is important to do AFTER destroying the character)

NewCharacter.Name = Player.Name -- Change the new character's name to the player's name (Roblox does this automatically for player characters)
Player.Character = NewCharacter -- Sets the player's default character to the new one
NewCharacter:PivotTo(OldCFrame) -- Pivots the new character to the CFrame of the old one (Again, this is not required)
NewCharacter.Parent = workspace -- And finally parents the new character to the workspace
1 Like

I’m sorry… But where should I put a script like this and is it a LocalScript?

I’d assume it’s a server script as otherwise the changes wouldn’t reflect for other players.
Based off your existing code, I’d place it in the if newCharacter then block, replacing the NewCharacter variable in the new code with the existing newCharacter variable.