Team Change Gui in a Tool?

Hi, I am currently trying to make a tool that will change a players team. Here is how I’m doing it. I have a Gui pop up when you hold the tool gui3
and for example, when you click the blue button it will Enable a script inside the tool that when you touch it, it will change the players team to the blue team. But I am having issues doing this because when I use a LocalScript inside the TextButton to Enable the team change script, it only Enables the script for the LocalPlayer. I believe this is occurring because I am using a LocalScript, so I used a normal Script instead and the Team Change Script didn’t even become enabled on the LocalPlayer. Here are my scripts

--This one is inside the blue textbutton
local frame = script.Parent.Parent.Parent.Parent.Parent.Character["Team Baton"]

script.Parent.MouseButton1Click:Connect(function()

frame.Blue.Disabled = false

frame.Green.Disabled = true

frame.LD.Disabled = true

frame.Purple.Disabled = true

frame.Red.Disabled = true

frame.Trainee.Disabled = true

end)

--This is the one inside the Tool
script.Parent.Handle.Touched:Connect(function(hit)

local name = hit.parent.name

local player = game.Players:FindFirstChild(name)

player.TeamColor = BrickColor.new("Navy blue")

player.Neutral = false

end)

Here is what the whole thing looks like in the explorer window (I know it’s messy)
explorer

Anyways, if you know what the issue is or how to fix it, anything helps and I will try everything.
Thanks and have a nice day! :slight_smile:

1 Like

Use F9 (Developer console). They have an area for scripts.

1 Like

Hey!

So, I would recommend keeping the GUI handling from the LocalScript, then you can have a RemoteEvent fire when the player presses the gui.

I would recommend having a value that says which team that the tool needs to switch the player’s team to, instead of having a script for each team.

This is some code to get you in the right direction:

Local script:

local tool = script.Parent
local event = game:GetService("ReplicatedService"):WaitForChild("TeamBatonEvent")
local whichTeam = script.Parent:WaitForChild("whichTeam")

whichTeam:GetPropertyChangedSignal("Value"):Connect(function()

local team = whichTeam.Value

event:FireServer(team)

end)

Server script:

local event = game:GetService("ReplicatedService"):WaitForChild("TeamBatonEvent")


event.OnServerEvent:Connect(function(player, team)

teamcheck = game.Teams:FindFirstChild(team)

if teamcheck then
player.Team = teamcheck

end
end)

For the gui’s have a localscript that changes a value and makes the value the name of the team that they pressed.(make sure it is a string value).

See if this helps, if not come back and we can help you further.

2 Likes

Thanks so much for your reply, I am trying this now! :smiley: Quick question though, would I put the server script in ServerScriptService?

Yes, I would recommend putting it there.

Hi, sorry for the delay, I was wondering how would I make it so when the player touched the baton it changes their team to the chosen one? Because we didn’t finish it entirely…

TeamBaton.rbxm (3.0 KB)

Upload this into your game, you will need to delete all of your scripts for the baton and the batongui. You then need to follow all of my instructions I provided in the model.

Let me know if this doesn’t work, and I will help you!
Best of luck!

1 Like

So I tried it and it doesn’t work and I get this error in Output “Players.SmithGaming_YT.Backpack.Team Baton.Handle.TeamBaton:33: invalid argument #3 (string expected, got Instance)”

Alright, let me try out and see what happens.

1 Like

Ok, here is the whole thing in a RBXL file. Team Baton.rbxl (31.7 KB)

Hey! Got it to work: I forgot to reset the GUI’s visibility, so I fixed that. TeamBatonFixed.rbxl (31.8 KB)

Just remember that the Teams have to already exist for this to work, if you wanted it to create a team for you if it wasn’t there already that would take some more coding.

1 Like

Thanks so much!!! :smiley: 30 characters

Not a problem man! Glad I was able to help!

1 Like