So, I'm trying to make a game like CS:GO on Roblox, but I have a problem. I am having problems making team-based characters.
Let's say everyone in Team 1 is supposed to have Character 1 and Team 2 is supposed to have Character 2. My attempt was to clone Character 1 into StarterPlayer and rename it to StarterCharacter if the player is inside Team 1. Then, when the player's character has loaded, StarterCharacter gets removed. The same with Team 2.
Now, when I loaded in, my character appearance didn't change and I was still me. The script is a serverscript and is placed inside StarterPack. I am also getting no error in the output.
Here's the code: (I'm kinda new to scripting)
local StarterCharacter1 = game.ServerStorage.TModel local StarterCharacter2 = game.ServerStorage.CTModel --Terrorist Side game.Players.PlayerAdded:connect(function(plr) if script.Parent.Parent.TeamColor == ("Maroon") then StarterCharacter1:Clone().Parent = game.StarterPlayer game.StarterPlayer.TModel.Name = "StarterCharacter" local Pos = plr.Character:GetPrimaryPartCFrame() plr:LoadCharacter() plr.Character:SetPrimaryPartCFrame(Pos) if plr.Character:FindFirstChild("ForceField") then plr.Character["ForceField"]:Destroy() game.StarterPlayer.StarterCharacter:Remove() end end end) --Counter Terrorist Side game.Players.PlayerAdded:connect(function(plr) if script.Parent.Parent.TeamColor == ("Navy Blue") then StarterCharacter2:Clone().Parent = game.StarterPlayer game.StarterPlayer.CTModel.Name = "StarterCharacter" local Pos = plr.Character:GetPrimaryPartCFrame() plr:LoadCharacter() plr.Character:SetPrimaryPartCFrame(Pos) if plr.Character:FindFirstChild("ForceField") then plr.Character["ForceField"]:Destroy() game.StarterPlayer.StarterCharacter:Remove() end end end)
A player's TeamColor is not a string. Please use BrickColor.new(Color)
instead.
Here's a link to the page about Player.TeamColor
: https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor
Also, based on the script.Parent.Parent
, is this in a LocalScript?
If so, please make sure this is in a regular script inside of either Workspace or ServerScriptService.
local StarterCharacter1 = game.ServerStorage.TModel local StarterCharacter2 = game.ServerStorage.CTModel game.Players.PlayerAdded:connect(function(plr) if plr.TeamColor == BrickColor.new("Maroon") then StarterCharacter1:Clone().Parent = game.StarterPlayer game.StarterPlayer.TModel.Name = "StarterCharacter" local Pos = plr.Character:GetPrimaryPartCFrame() plr:LoadCharacter() plr.Character:SetPrimaryPartCFrame(Pos) if plr.Character:FindFirstChild("ForceField") then plr.Character["ForceField"]:Destroy() game.StarterPlayer.StarterCharacter:Remove() end elseif plr.TeamColor == BrickColor.new("Navy Blue") then StarterCharacter2:Clone().Parent = game.StarterPlayer game.StarterPlayer.CTModel.Name = "StarterCharacter" local Pos = plr.Character:GetPrimaryPartCFrame() plr:LoadCharacter() plr.Character:SetPrimaryPartCFrame(Pos) if plr.Character:FindFirstChild("ForceField") then plr.Character["ForceField"]:Destroy() game.StarterPlayer.StarterCharacter:Remove() end end end)