Team change GUI Scirpt

So by the title, probably seems to be a pretty simple solution? Well, although it probably is, it isn’t what you think. So I have this GUI that changes the player’s team, changes a few text labels so on and so forth, the problem is, it doesn’t work. The script was written by another user, but it still doesn’t work, and the post is pretty much dead at this point. So I am reposting here.

Script:

local tweenService = game:GetService("TweenService")
local lighting = game:GetService("Lighting")
local _workspace = game:GetService("Workspace")
local players = game:GetService("Players")
local teams = game:GetService("Teams")

local player = players.LocalPlayer
local teamVal = script.Parent.Team
local team = "Class D"

local teams = {
	[1] = "Class D",
	[2] = "Foundation Personnel",
	[3] = "Security Department",
	[4] = "Medical Department",
	[5] = "Scientific Department",
	[6] = "Ethics Committee",
	[7] = "Department of External Affairs",
	[8] = "Mobile Task Force",
	[9] = "Rapid Response Team",
	[10] = "Internal Security Department",
	[11] = "Intelligence Agency",
	[12] = "Facility Executive",
	[13] = "Chaos Insurgency",
	[14] = "SCP",
	[15] = "O5 Command"
}

teamVal:GetPropertyChangedSignal("Value"):Connect(function()
	if not table.find(teams, teamVal.Value) then return end

	if teamVal.Value == "Class D" or teamVal.Value == "O5 Command" then
		script.Parent.Button1.Visible = false
	end

	if teamVal.Value == "Foundation Personnel" or teamVal.Value == "SCP" then
		script.Parent.Button1.Visible = true
	end

	team = teams[teamVal.Value]
	script.Parent["Team Lable"].Text = "Current Team Selected: "..team..""
end)

player.PlayerGui.MainMenu.GUIVis.Value = 1

script.Parent.Play.TextButton.MouseButton1Click:Connect(function()
	player.Team = teams[team]
	

	local tween = tweenService:Create(script.Parent.Parent.Black,
		TweenInfo.new(
			0.2,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.Out,
			0,
			true
		), {BackgroundTransparency = 0}
	):Play()

	local a, e = pcall(function()
		player.Character.Humanoid.MaxHealth = 0
		player.Character.Humanoid.Health = 0

		script.Parent.EffectHover:Play()

		wait(0.2)

		script.Parent.Visible = false
		script.Parent.Parent.Main.Visible = true
		script.Parent.Parent.Enabled = false

		lighting.MenuBlur.Size = 0
		_workspace.Camera.CameraType = Enum.CameraType.Custom

		player.PlayerGui.MainMenu.GUIVis.Value = 0
	end)

	if not a then
		warn(string.format("Something went wrong :C \n %s", e))
	end
end)

GUI File if you’re interested:
MainGUI.rbxm (15.3 KB)

2 Likes

are there any errors with the script?

You cannot change the player’s team from the client. You would need to set up a RemoteEvent and change the team via the server. BUT, you would need to secure this RemoteEvent from exploiters. Let me know if further explanation is needed.

2 Likes

No, no errors, at least none on the console.

I see, how would you recommend going about setting up the server script so that It knows A. when the arrows in the GUI are pressed and B. which teams there all are?

I dont think there is a script (section of the script) that checks what team is selected in this script, but you can use a remote event to pass in the arguments. and for the teams there are, you can make the same table in the server script

First of all, if there are any requirements for certain teams (such as ranks or gamepasses) you must declare them both in the client script and the server script. Everything that is currently set up in the client script can stay except for:

That line will be replaced with the RemoteEvent. Here is how we would go about doing so:

First, obviously, create a RemoteEvent and parent it to ReplicatedStorage. Name the RemoteEvent TeamEvent just so it is easy to recognize.

In the client script, you would replace the above line with:

game.ReplicatedStorage:WaitForChild("TeamEvent"):FireServer(team)

The server script will have the following:

game.ReplicatedStorage:WaitForChild("TeamEvent").OnServerEvent:Connect(function(player,team)
     player.Team = game.Teams[team]
end)

Again, if there are any requirements for the teams, this will need to be revised!

1 Like

How would you recommend doing this, I’m not very advanced at scripting so sorry if this is painfully obvious.

No worries. Happy to help you out.

Step 1:
Insert a new object in ReplicatedStorage using the studio explorer tab. Create a RemoteEvent, and rename it to TeamEvent.
image

Step 2:

In the local script (the one you provided) change this line:

to this:

game.ReplicatedStorage:WaitForChild("TeamEvent"):FireServer(team)

Step 3:

Create a new Script in ServerScriptService. The name of this script does not matter.
image

Step 4:

Open the script you just created, and paste the following code into it:

game.ReplicatedStorage:WaitForChild("TeamEvent").OnServerEvent:Connect(function(player,team)
     player.Team = game.Teams[team]
end)

[Step 5:]

That should be it. PLEASE NOTE: If you need requirements for certain teams, such as rank requirements or gamepasses, this MUST be revised, or else exploiters can easily bypass it. Let me know if that is something you need. Otherwise, this should work perfectly, assuming the rest of the code is fine.

Let me know if this helps!

1 Like

I think he needs help with actually getting the team the player wants to change to

Yeah it was mostly this, and securing the remote event, but this was still helpful nevertheless as I was unsure at first which line to replace. Sorry for being vague in my reply.

Im not sure what you mean by securing remote events, but you can check

that in the server, so regardless of what the client sends, the server is the one deciding wether to give the player the team or not

So basically as long as there is no serverside backdoor I should be fine?

Your GUI should be working fine. All you need to do is the RemoteEvent that I gave instructions for and, yes, everything should be fine.

Also, line 49 is now erroring out in my local script, the line that was changed.

21:58:52.475  FireServer is not a valid member of BindableEvent "ReplicatedStorage.TeamEvent"  -  Client - ValueScript:49

Could you please provide the contents of the error?

I see. You created a BindableEvent, not a RemoteEvent.

image

Delete the TeamEvent and create a RemoteEvent instead, and make sure to rename it again.

Ah I must have missclicked, let me try again.

The only issue now is that the arrow GUI buttons I added don’t change which team is selected and the text label I have at the top doesn’t show what team is selected, I’d imagine this is probably another issue in the script however, no errors though.

If this is your only code regarding the GUI buttons, there is not any functions that detect your method of changing the team or at least I don’t think.
(by “this code” I’m referring to the code you sent at the very beginning)