I'm new to scripting, and my team change gui is not working

I am pretty new to scripting, and I started to work on a Team Change GUI, it works but other players don’t see the changes. I am using Remove Events, not sure if I’m doing it correctly. I will supplement some screenshots and code bars of my explorer, and my scripts.

Team change to guard. These team change localscripts are inside of the TeamGua = Guard team, and TeamInm, inmate team. (TextButtons)

local Player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local Gui = script.Parent.Parent.Parent
local Upd = script.Parent.Parent
local Ingame = script.Parent.Parent.Parent.Parent.Ingame

script.Parent.MouseButton1Click:Connect(function()
    Player.Team = Teams:FindFirstChild("Guard")
    game.ReplicatedStorage.TeamChange:FireServer()
    Gui.Visible = false
    Upd.Visible = false
    Ingame.Visible = true
    local StarterGui = game:GetService("StarterGui")
    StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
end)

Team change to inmate

Script above, but
Player.Team = Teams:FindFirstChild("Guard"))
Guard is replaced by Inmate.

My remove event handler in serverscriptservice

game.ReplicatedStorage.TeamChange.OnServerEvent:connect(function(Player)
Player:LoadCharacter()

end)

Some screenshots from my explorer

image

image

image

1 Like

You are doing this on a local script. You need to handle the team changing on the server, not the client.

to achieve this you would need to use a remote event to tell the server to change the players team. You can read up on remote events here on the API:

Your code should look something like this:

-- server
RemoteEvent.OnServerEvent:Connect(function(plr,Team)
plr.Team = game.Teams:FindFirstChild(Team)
end)

-- local script
Script.Parent.MouseButtonlClick:Connect(function()
local team = 'Red Team'
RemoteEvent:FireServer(team) -- You only need to put in the team because player is by default the first variable
end)

Edited to fix my stupidity lol, thanks @ReturnedTrue

1 Like

Little problemo here:

Make sure to use Team without the quotation marks, otherwise it’ll quite literally pass ‘Team’.

3 Likes