Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
unmiss 337 Moderation Voter
9 years ago

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

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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.

Ad
Log in to vote
-1
Answered by 9 years ago

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)
0
does not work for anyone now unmiss 337 — 9y
0
maybe it is conflicting with the black statements unmiss 337 — 9y
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 unmiss 337 — 9y
0
I'm sorry for that poor answer, I made some changes to make it easier to understand dragonkeeper467 453 — 9y
View all comments (2 more)
0
really? dragonkeeper467 453 — 9y
0
who gave me another bad rep? i fixed my answer, how is that deserve a bad rep??? dragonkeeper467 453 — 9y

Answer this question