Changing team onclick

So I am trying to make it so when you click a button it changes your team.

I get this error


local button = script.Parent.Frame.Button
local mainframe = script.Parent.TeamchangerUI
local Team1 = mainframe:WaitForChild("Team1")
local Team2 = mainframe:WaitForChild("Team2")
local team2 = game.Teams["Team 2"]
local team1 = game.Teams["Team 1"]



button.MouseButton1Click:Connect(function()
	local mainframe = script.Parent.TeamchangerUI
	
	if mainframe.Visible == true then
		mainframe.Visible = false
		print("Mainframe was closed")
	elseif mainframe.Visible == false then
		mainframe.Visible = true
		print("Mainframe has been opened")
	end
	
end)


Team1.MouseButton1Click:Connect(function(p)
	local player = game.Players.LocalPlayer
	player.Team = game:GetService("Teams")[team2]
end)

Team2.MouseButton1Click:Connect(function(p)
	local player = game.Players.LocalPlayer
	player.Team = game:GetService("Teams")[team1]
end)

You’ve already defined the variables data as a team Instance. Why are you indexing them again??

player.Team = team2
player.Team = team1
2 Likes

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