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

How would I be able to make this textbutton team-only functional?

How exactly would I be able to detect if a player is on a team. This GUI opens another GUI, but I only want it to do the stuff in the script if the player is on one of ***two *** select teams.

local black = false

function codrop()
	if black == false then
script.Parent:TweenPosition(UDim2.new(0, 0,0, 350), "In", "Linear", 2)
wait(0.1)
black = true
script.Parent.Parent.CourtMenu.Text = "Close CM"
	elseif black == true then
script.Parent:TweenPosition(UDim2.new(0, 1500,0, 350), "Out", "Linear", 1)
black = false
script.Parent.Parent.CourtMenu.Text = "Court Menu (CJ)"

end end
	
script.Parent.Parent.CourtMenu.MouseButton1Down:connect(codrop)

edit: or... maybe the GUI button you click on to open this item would only be visible to two teams, rather than it just not doing anything

2 answers

✓ Accepted answer

What You Need To Do

There is a Property in the Player called TeamColor.

Image

There is also a Property in the Team object called TeamColor

Image

If you compare these two proeperties, to check if they're equivelant, as a prerequisite to any further code.. then it will only allow the specified TeamColor use the button.


Code

local black = false
local plr = game.Players.LocalPlayer --The Player
local team = game.Teams.Blue --The Team You Want

function codrop()
	if not black then
		script.Parent:TweenPosition(UDim2.new(0, 0,0, 350), "In", "Linear", 2)
		wait(0.1)
		black = true
		script.Parent.Parent.CourtMenu.Text = "Close CM"
	else
		script.Parent:TweenPosition(UDim2.new(0, 1500,0, 350), "Out", "Linear", 1)
		black = false
		script.Parent.Parent.CourtMenu.Text = "Court Menu (CJ)"
	end
end

script.Parent.Parent.CourtMenu.MouseButton1Down:connect(function()
	if plr.TeamColor == team.TeamColor then --Check if they match
		codrop() --Call the function
	end
end)

NOTE: This should be a LocalScript in order for it to work.

Use a local script to run this code. On line 4 on the if loop change the color BrickColor.new("White") to the color of the team you want to access the gui. Then put the code to open the gui inside the if loop. It will check if the player is on the right team when the function is called and then if the player is on the team then it will open the gui, if the player is not on the team it will exit the function and therefore ignore the open gui code.

player = game.Players.LocalPlayer

function codrop()
	if player.TeamColor == BrickColor.new("White") then
		--gui code
	end
end

script.Parent.Parent.CourtMenu.MouseButton1Down:connect(codrop)

6 comments

0

does not work for anyone now

0

maybe it is conflicting with the black statements

0

I put it in another script to make it invisible if they aren't on the team but it still works for everyone now... UGH

0

I'm sorry for that poor answer, I made some changes to make it easier to understand

0

really?

0

who gave me another bad rep? i fixed my answer, how is that deserve a bad rep???

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