Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My player change team color script is not working?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)

Ad

Answer this question