Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My player change team color script is not working?

So I am having trouble changing a players team. It might sound simple but it really isn't working when I try this VERY easy script. Help?




local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local teamName = ("TSE")
	  player.TeamColor = BrickColor.new("Really black")
	player.LoadCharacter()
	script.Parent.Parent.Enabled = false
end)







1 answer

###This happens because you are using LoadCharacter on the client, when it is server-side only. You are also changing the team on the client, and it will not replicate because of this. A fix would be to use RemoteEvents.

-- Server script, place in ServerScriptService

local ChangeTeam = Instance.new("RemoteEvent")
ChangeTeam.Name = "ChangeTeam"
ChangeTeam.Parent = game:GetService("ReplicatedStorage")

ChangeTeam.OnServerEvent:Connect(function(plr, teamColor)
    plr.TeamColor = teamColor
    plr:LoadCharacter()
end) 

-- back in your localscript VVVV
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local teamName = "TSE"
    game:GetService("ReplicatedStorage").ChangeTeam:FireServer(
        BrickColor.new("Really black")
    )
    script.Parent.Parent.Enabled = false
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.