Character does not change after selecting a team

When the player selects a team using the GUI (either “Guard” or “Infected”), the server receives the event and attempts to replace the character with a custom model (GuardModel or InfectedModel). However, instead of spawning the selected custom character, Roblox spawns the default character.

Here is a video

Here is my serverscript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

local chooseEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ChooseTeam")
local modelsFolder = ReplicatedStorage:WaitForChild("Models")

local function replaceCharacter(player, templateModel)
	local customModel = templateModel:Clone()
	customModel.Name = player.Name

	local root = customModel:FindFirstChild("HumanoidRootPart")
	if not root then
		warn("Where is HumanoidRootPart bro?")
		return
	end
	customModel.PrimaryPart = root

	player:LoadCharacter(customModel)
end

chooseEvent.OnServerEvent:Connect(function(player, teamName)
	if teamName == "Guard" then
		player.Team = Teams.Guard
		replaceCharacter(player, modelsFolder:WaitForChild("GuardModel"))
	elseif teamName == "Infected" then
		player.Team = Teams.Infected
		replaceCharacter(player, modelsFolder:WaitForChild("InfectedModel"))
	else
		player.Team = Teams.Choosing
		player:LoadCharacter()
	end
end)

Here is LocalScript

local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local player = Players.LocalPlayer
local chooseEvent = RepStorage:WaitForChild("Events"):WaitForChild("ChooseTeam")
local ChooseGui = RepStorage:WaitForChild("ChooseGui")
local ChoosingTeam = Teams:WaitForChild("Choosing")

local function setupGui()
	local guiClone = ChooseGui:Clone()
	guiClone.ResetOnSpawn = false
	guiClone.Parent = player:WaitForChild("PlayerGui")

	local infectedButton = guiClone.Frame.InfectedButton
	local guardButton = guiClone.Frame.GuardButton

	infectedButton.MouseButton1Click:Connect(function()
		chooseEvent:FireServer("Infected")
	end)

	guardButton.MouseButton1Click:Connect(function()
		chooseEvent:FireServer("Guard")
	end)

	local function updateGui()
		guiClone.Enabled = (player.Team == ChoosingTeam)
	end

	updateGui()
	player:GetPropertyChangedSignal("Team"):Connect(updateGui)
end

setupGui()
player.CharacterAdded:Connect(setupGui)

Teams: Infected, Guard, Choosing

You can’t morph the character by passing it into the LoadCharacter method. You have to switch the player’s character and clone all the character scripts.

I made a quick lil morph function 4 u

local function Morph(Player:Player, MorphModel:Model)
	local PlayerModel = Player.Character
	if not PlayerModel then return end
	
	local NewModel = MorphModel:Clone()
	NewModel.Name = Player.Name
	Player.Character = NewModel
	
	NewModel:PivotTo(PlayerModel.PrimaryPart.CFrame)
	
	for Index, Child in game.StarterPlayer.StarterCharacterScripts:GetChildren() do
		Child:Clone().Parent = NewModel
	end
	
	NewModel.Parent = workspace
	PlayerModel:Destroy()
end
1 Like

True, :LoadCharacter() doesnt even accept any arguments..

Player:LoadCharacter() returns nothing than your model character roblox

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

local chooseEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ChooseTeam")
local modelsFolder = ReplicatedStorage:WaitForChild("Models")

local teams={
teams0={
["Choosing"]=Teams.Choosing,
["Guard"]=Teams.Guard,
["Infected"]=Teams.Infected
},
teamsmodel={
--["Choosing"]="NONE",
["Guard"]=modelsFolder.GuardModel,
["Infected"]=modelsFolder.InfectedModel
},
}

local function replaceCharacter(player: Player, templateMode: Model)
player.Character:Destory()
	local customModel = templateModel:Clone()
	customModel.Name = player.Name

	local root = customModel:FindFirstChild("HumanoidRootPart")
	if not root then
		warn("Where is HumanoidRootPart bro?")
		return
	end
	customModel.PrimaryPart = root
player.Character = customModel
customModel.Parent = Workspace
end


-- terrible looking code...
chooseEvent.OnServerEvent:Connect(function(player: Player, teamname: String)
for i,v in teams.teams0 do
for i0,v0 in teamsmodel do
if teamname = i and not player.Team == v then
player.Team = v
end
if teamname = i0 then
replaceCharacter(player, v0)
end
end
end
end)

Also you don’t need to use if alot, you can use like this dictionaries inside tables

(Thanks, Updated)

Randomly popped in but this would error. You’d pass a string of “NONE” into the function, and it would try cloning the string… Just a little feedback

1 Like

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