Unable to change teams "/checkin" works (used to log in police team), but "/checkout" (log off) does not work!

Yes… you seen the title.

Hello, I own a Hood (Gangster Game/RP), and I am having problems. I have a police team named ‘CPD’ (Chicago Police Department for abbriv.) and /checkin works when you try to log on the police team but /checkout does not. Now, I did not make this script, so I’m planning to revamp this script however I need somebody’s help in order for me to help me find alternatives to fix because sometimes Lua wishes not to cooperate with Roblox itself.

I have a RemoveEvent in ReplicatedStorage (for CPD), I just added ‘Citizen’ as RemoteEvent in ReplicatedStorage and copied the same way you would go to teams. However, this still does not work. I’ll show a pic and script:

(THERE ARE MULTIPLE SCRIPTS FOR THIS, SO BE ALERT!):


Found in ServerScriptService

'game.ReplicatedStorage.CPD.OnServerEvent:Connect(function(Player)
if Player:IsInGroup(16525198) then
Player.TeamColor = BrickColor.new(‘Storm blue’)
Player:LoadCharacter()
end
end)
game.ReplicatedStorage.Citizen.OnServerEvent:Connect(function(Player)
if Player:IsInGroup(16525198) then
Player.TeamColor = BrickColor.new(‘White’)
Player:LoadCharacter()
end
end)

game.ReplicatedStorage.CFDP.OnServerEvent:Connect(function(Player)
if Player:IsInGroup(16525198) then
Player.TeamColor = BrickColor.new(‘Hurricane grey’) --Was hurricane grey/hurricane gray
Player:LoadCharacter()
end
end)


Found in StarterCharacterScripts

'local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)

local Player = game.Players.LocalPlayer

Player.Chatted:Connect(function(Msg)
if Msg == ‘/checkin’ then
ReplicatedStorage.CPD:FireServer()
elseif Msg == ‘/checkout’ then
ReplicatedStorage.SigningOut:FireServer()
end
end)

Player.Chatted:Connect(function(Msg)
if Msg == ‘/checkinfd’ then
ReplicatedStorage.CFDP:FireServer()
elseif Msg == ‘/checkoutfd’ then
ReplicatedStorage.SigningOut:FireServer()
end
end)’


Oh and look at this, what are so familiar about these? (even same team brick color)


Anyways, please help. I do not understand this!

Try this for your server script

local function changeTeamColor(Player, color)
    if Player:IsInGroup(16525198) then
        Player.Neutral = false
        Player.TeamColor = BrickColor.new(color)
        if Player.Character then
            Player:LoadCharacter()
        end
    end
end

game.ReplicatedStorage.CPD.OnServerEvent:Connect(function(Player)
    changeTeamColor(Player, 'Storm blue')
end)

game.ReplicatedStorage.Citizen.OnServerEvent:Connect(function(Player)
    changeTeamColor(Player, 'White')
end)

game.ReplicatedStorage.CFDP.OnServerEvent:Connect(function(Player)
    changeTeamColor(Player, 'Hurricane grey')
end)

game.ReplicatedStorage.SigningOut.OnServerEvent:Connect(function(Player)
    if Player:IsInGroup(16525198) then
        Player.Neutral = true
        Player:LoadCharacter()
    end
end)

In this version, the server script defines a function ‘changeTeamColor’ that takes a player and a color as arguments. This function checks if the player is in the group, sets the player’s ‘Neutral’ property to false (which allows their team color to be changed), changes their team color, and then respawns them if they are not currently respawning. The ‘SigningOut’ event sets the player’s ‘Neutral’ property to true, which makes them not belong to any team.

@qw3rty_l0l

Once I copied and pasted the script, IT DOES WORK however once I did /checkout again, I spawned mid-air out of nowhere and I have like (12) spawn locations

AFTER: (because it had some codes/red lines, so its fixed on that)

Just check out the video I have made (because it still shows Police-Related GUI stuff and you’ll see.

You spawn in mid air because of load character

but try this:

local function changeTeamColorAndGui(Player, color, guiName)
    if Player:IsInGroup(16525198) then
        Player.Neutral = false
        Player.TeamColor = BrickColor.new(color)
        if Player.Character then
            Player:LoadCharacter()
        end
        -- Change GUI
        local gui = game.ReplicatedStorage:FindFirstChild(guiName)
        if gui then
            local playerGui = Player:FindFirstChildOfClass('PlayerGui')
            if playerGui then
                playerGui:ClearAllChildren()
                gui:Clone().Parent = playerGui
            end
        end
    end
end

game.ReplicatedStorage.CPD.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'Storm blue', 'CPDGui')
end)

game.ReplicatedStorage.Citizen.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'White', 'CitizenGui')
end)

game.ReplicatedStorage.CFDP.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'Hurricane grey', 'CFDPGui')
end)

game.ReplicatedStorage.SigningOut.OnServerEvent:Connect(function(Player)
    if Player:IsInGroup(16525198) then
        Player.Neutral = true
        Player:LoadCharacter()
        local playerGui = Player:FindFirstChildOfClass('PlayerGui')
        if playerGui then
            playerGui:ClearAllChildren()
        end
    end
end)

This script assumes that you have GUIs named ‘CPDGui’, ‘CitizenGui’, and ‘CFDPGui’ in your ReplicatedStorage. When a player changes team, their GUI is replaced with the corresponding team GUI. When a player signs out, all GUIs are cleared.

Yes… I made it where GUI is fixed for both teams…

I have a Spawn Location block where you can finally spawn after /checkout. How do I also make that happen? I think I’m nearly done with this script.

It’s pretty simple but after load character in change team color function teleport the Player to a part which would be your spawns. if you need that quickly made reply to this and let me know. sorry for the late response lol

Yeah… I’m in a rush. That could help.

Also, please check your DMs. I have sent you something.

I’m sorry for the late response as I had things to do but here is the code.

  • This is assuming you have ChangeTeamColorSpawns folder in workspace (you can of course change the path) and multiple children inside that folder that sets the HRP.CFrame to a random child inside that folder.
local function changeTeamColorAndGui(Player, color, guiName)
    if Player:IsInGroup(16525198) then
        Player.Neutral = false
        Player.TeamColor = BrickColor.new(color)
        if Player.Character then
            Player:LoadCharacter()
            local spawns = game.Workspace.ChangeTeamColorSpawns:GetChildren()
            local randomSpawn = spawns[math.random(#spawns)]
            Player.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame
        end
        local gui = game.ReplicatedStorage:FindFirstChild(guiName)
        if gui then
            local playerGui = Player:FindFirstChildOfClass('PlayerGui')
            if playerGui then
                playerGui:ClearAllChildren()
                gui:Clone().Parent = playerGui
            end
        end
    end
end

game.ReplicatedStorage.CPD.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'Storm blue', 'CPDGui')
end)

game.ReplicatedStorage.Citizen.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'White', 'CitizenGui')
end)

game.ReplicatedStorage.CFDP.OnServerEvent:Connect(function(Player)
    changeTeamColorAndGui(Player, 'Hurricane grey', 'CFDPGui')
end)

game.ReplicatedStorage.SigningOut.OnServerEvent:Connect(function(Player)
    if Player:IsInGroup(16525198) then
        Player.Neutral = true
        Player:LoadCharacter()
        local playerGui = Player:FindFirstChildOfClass('PlayerGui')
        if playerGui then
            playerGui:ClearAllChildren()
        end
    end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.