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
