Making a SurfaceGui text button script only work if a player clicking it has a certain team color

  1. What do you want to achieve? A surfacegui text button in which the script inside it only runs if the player who clicked it has a certain team color.

  2. What is the issue? Everytime I try to make the button’s script work by getting the players teamcolor value, it gives me the error “attempt to index nil with ‘TeamColor’”

  3. What solutions have you tried so far? The 2nd script I showed all the way below.

script.Parent.MouseButton1Click:connect(function(GetCar)
	
		Mod = game.ServerStorage.TestCar    
		clone = Mod:clone()
		clone.Parent = workspace
		clone:MakeJoints()
		script.Parent.Parent.SpawnCar2.Visible = true
		script.Parent:Destroy()
		
end)

This was my try at trying to achieve my goal (which inevitably gave me that “attempt to index nil with ‘TeamColor’” error. (Below)

script.Parent.MouseButton1Click:connect(function(player)
    if player.TeamColor == "Bright blue" then
        Mod = game.ServerStorage.TestCar 
        clone = Mod:clone()
        clone.Parent = workspace
        clone:MakeJoints()
    end
end)

I’m not 100% sure, but I believe TeamColor runs on BrickColors. You might wanna try replacing your line with

if player.TeamColor == BrickColor.new("Bright blue") then

Gui buttons don’t return the player who clicked them.

It’s a surfacegui not a screengui if that’s what you’re talking about

It doesn’t matter if it’s in a surface gui or not, gui buttons don’t return the player who clicked. GuiButton.MouseButton1Click doesn’t pass a player

Your SurfaceGui should be inside of the StarterGui. Just make the SurfaceGui’s Adornee the part where you would like it to display and get the player with a local script inside of the button whenever it’s clicked.

1 Like

You can try redirecting it to the teams instead of the team color.

if player.Team == game.Teams["Team Name"]