Teams system not working

So I created guis that pops up at the start of the game in which you chose what team you want to be on (very similar to jailbreak). It works perfectly fine one player but when I test it locally, sometimes the guis dont show up. I understand this is a problem with my script being a normal script, but I need help figuring out what would go in a local script and what should stay in the normal script. Also, do these scripts go in replicated storage or server storage.

local TeamService = game:GetService(“Teams”)
local playerService = game:GetService(“Players”)

local playerAlreadyJoined = false

playerService.PlayerAdded:Connect(function( p)

p.CharacterAdded:Connect(function(c)
	if playerAlreadyJoined == false then

		local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
		local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")

		local Blur = game.Lighting.Blur
		local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
		local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
		wait()
		c:Remove()
		game.Players.CharacterAutoLoads = false

		StartGui.Enabled = true
		Blur.Size = 24
		--PoliceJoinCommands--------------------------------------------------------------------
		PoliceButton.MouseButton1Down:Connect(function()
			p.TeamColor = BrickColor.new("Bright blue")
			StartGui.Enabled = false
			Blur.Size = 0

			game.Players.CharacterAutoLoads = true
			ui.Enabled = true
			playerAlreadyJoined = true
			p:LoadCharacter()
			local Keycard = game.ServerStorage.Keycard:Clone()
			Keycard.Parent = p:WaitForChild("Backpack")
		end)
		--PrisonerJoinCommands-------------------------------------------------------------------
		PrisonerButton.MouseButton1Down:Connect(function()
			p.TeamColor = BrickColor.new("Br. yellowish orange")
			StartGui.Enabled = false
			Blur.Size = 0

			game.Players.CharacterAutoLoads = true
			ui.Enabled = true
			playerAlreadyJoined = true
			p:LoadCharacter()
		end)
	end

end)

end)

1 Like

There were some weird characters, but I fixed.

Try this:

local TeamService = game:GetService("Teams")

local playerService = game:GetService("Players")

local playerAlreadyJoined = false

playerService.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		if playerAlreadyJoined == false then
			local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
			local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")
			local Blur = game.Lighting.Blur
			local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
			local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
			wait()
			c:Remove()
			game.Players.CharacterAutoLoads = false

			StartGui.Enabled = true
			Blur.Size = 24
			--PoliceJoinCommands--------------------------------------------------------------------
			PoliceButton.MouseButton1Down:Connect(function()
				p.TeamColor = BrickColor.new("Bright blue")
				StartGui.Enabled = false
				Blur.Size = 0

				game.Players.CharacterAutoLoads = true
				ui.Enabled = true
				playerAlreadyJoined = true
				p:LoadCharacter()
				local Keycard = game.ServerStorage.Keycard:Clone()
				Keycard.Parent = p:WaitForChild("Backpack")
			end)
			--PrisonerJoinCommands-------------------------------------------------------------------
			PrisonerButton.MouseButton1Down:Connect(function()
				p.TeamColor = BrickColor.new("Br. yellowish orange")
				StartGui.Enabled = false
				Blur.Size = 0

				game.Players.CharacterAutoLoads = true
				ui.Enabled = true
				playerAlreadyJoined = true
				p:LoadCharacter()
			end)
		end
    end)
end)

You cannot detect a click in a serverscript fromwhat I know

Ya this is my first post so idk why my characters got messed up on it but the problem is not a syntax error

It seems to work single player but idk locally

try this:
game.Players.PlayerAdded:Connect(function(p)
local playerAlreadyJoined = false
p.CharacterAdded:Connect(function(c)
if playerAlreadyJoined == false then

    			local PoliceButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Police")
    			local PrisonerButton = p:WaitForChild("PlayerGui"):WaitForChild("StartGui"):WaitForChild("Prisoner")

    			local Blur = game.Lighting.Blur
    			local StartGui = p:WaitForChild("PlayerGui"):WaitForChild("StartGui")
    			local ui = p:WaitForChild("PlayerGui"):WaitForChild("UI")
    			wait()
    			c:Remove()
    			game.Players.CharacterAutoLoads = false

    			StartGui.Enabled = true
    			Blur.Size = 24
    			--PoliceJoinCommands--------------------------------------------------------------------
    			PoliceButton.MouseButton1Down:Connect(function()
    				p.TeamColor = BrickColor.new("Bright blue")
    				StartGui.Enabled = false
    				Blur.Size = 0

    				game.Players.CharacterAutoLoads = true
    				ui.Enabled = true
    				playerAlreadyJoined = true
    				p:LoadCharacter()
    				local Keycard = game.ServerStorage.Keycard:Clone()
    				Keycard.Parent = p:WaitForChild("Backpack")
    			end)
    			--PrisonerJoinCommands-------------------------------------------------------------------
    			PrisonerButton.MouseButton1Down:Connect(function()
    				p.TeamColor = BrickColor.new("Br. yellowish orange")
    				StartGui.Enabled = false
    				Blur.Size = 0

    				game.Players.CharacterAutoLoads = true
    				ui.Enabled = true
    				playerAlreadyJoined = true
    				p:LoadCharacter()
    			end)
    		end

    	end)
    end)

So far it seems to work but if a player joins in on the middle of a game wouldn’t it glitch? So wouldn’t I need to use local scripts too?

probably not also, I made one edit and removed one line, see the screenshot below.

Put a Server Script in StarterGui:

local TeamService = game:GetService("Teams")

local playerService = game:GetService("Players")


playerService.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
             local playerAlreadyJoined = false
		if playerAlreadyJoined == false then
			local PoliceButton = script.Parent:WaitForChild("StartGui"):WaitForChild("Police")
			local PrisonerButton = script.Parent:WaitForChild("StartGui"):WaitForChild("Prisoner")
			local Blur = game.Lighting.Blur
			local StartGui = script.Parent:WaitForChild("StartGui")
			local ui = script.Parent:WaitForChild("UI")
			wait()
			c:Remove()
			game.Players.CharacterAutoLoads = false

			StartGui.Enabled = true
			Blur.Size = 24
			--PoliceJoinCommands--------------------------------------------------------------------
			PoliceButton.MouseButton1Down:Connect(function()
				p.TeamColor = BrickColor.new("Bright blue")
				StartGui.Enabled = false
				Blur.Size = 0

				game.Players.CharacterAutoLoads = true
				ui.Enabled = true
				playerAlreadyJoined = true
				p:LoadCharacter()
				local Keycard = game.ServerStorage.Keycard:Clone()
				Keycard.Parent = p:WaitForChild("Backpack")
			end)
			--PrisonerJoinCommands-------------------------------------------------------------------
			PrisonerButton.MouseButton1Down:Connect(function()
				p.TeamColor = BrickColor.new("Br. yellowish orange")
				StartGui.Enabled = false
				Blur.Size = 0

				game.Players.CharacterAutoLoads = true
				ui.Enabled = true
				playerAlreadyJoined = true
				p:LoadCharacter()
			end)
		end
	end)
end)

It may make no sense. But you won’t understand without trying.

Nah this glitched it so some of the blurs and guis didnt show up

The script dosent work :frowning: some parts dont show up

Also the blur, because it’s in a serverscript. It will be for everyone the blur. Start watching some tutorials first. get some info abt some fucntions etc

Thats why I asked shouldnt it be local script?
Edit: not the whole script just part of it

1 Like

A Server script in a Client gui doesn’t work I think

Yeah, use remoteevents that should work

Ok thanks I will try that-----

It works just not on multiplayer games