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

this script won't make inventory invisible for certain team??

Hi I am trying to code away that if a player is on team citizen the inventory goes invisible script in serverscriptservice

local Players = game:GetService("Players")



local Teams = game:GetService("Teams")



while wait() do



if Players.Team "Citizen" then



	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) 



	end



	end

3 answers

✓ Accepted answer

You'll gonna need to use a RemoteEvent for this. Make sure you have a Script in ServerScriptService, a LocalScript in StarterGui, and a RemoteEvent named EnableBackpack in ReplicatedStorage.

To detect if a play joins a Team, you use Team.PlayerAdded and Team.PlayerRemoved when a player leaves the Team.

Script in ServerScriptService:

local Teams = game:GetService("Teams")
local CitizenTeam = Teams.Citizen

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EnableBackpack = ReplicatedStorage.EnableBackpack

CitizenTeam.PlayerAdded:Connect(function(player) -- when a player joins this team
	EnableBackpack:FireClient(player, false) -- disable backpack
end)

CitizenTeam.PlayerRemoved:Connect(function(player) -- when a player leaves this team (player left/player's team set to neutral/player joined a new team)
	pcall(function() -- we use a pcall incase the player left to avoid errors (errors break the script, and maybe the whole game!!)
		EnableBackpack:FireClient(player, true) -- enable backpack
	end)
end)

LocalScript in StarterGui:

local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EnableBackpack = ReplicatedStorage:WaitForChild("EnableBackpack")

EnableBackpack.OnClientEvent:Connect(function(enabled)
	local success
	repeat
		-- we will use pcall() to avoid errors
		success = pcall(function()
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, enabled)
		end)
	until success -- loops the code until backpack was finally enabled/disabled
end)

1 comment

0

It works thanks!!

You're checking Players(the service) rather than each individual player. Try looping through each player in the server and checking their team instead.

while wait() do
	
	for i,v in pairs(Players:GetPlayers()) do

		--Check team and possibly disable gui

	end

end

1 comment

0

No errors and it does nothing still

You should not use a Script in ServerScriptService for this since the server cannot access their client, you can do all of this in the client. Use a LocalScript in StarterCharacterScripts.

local Players = game:GetService('Players')
local Teams = game:GetService('Teams')
local starterGui = game:GetService('StarterGui')
local Player = Players.LocalPlayer

if Player.Team == Team['Citizen'] then
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
else
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end

1 comment

0

This didn't work no errors either

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