Need help with team only sliding gate

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want my Gate to be exclusive to the Transit Authority team in my game.

  2. What is the issue?
    I’m too crappy to figure out when I need to check what team the player is on.

  3. What solutions have you tried so far?
    Well, I tried looking on the DevForum, but none of them fit my situation.

Here’s the script I tried:

local trigger = script.Parent
local gate = script.Parent.Parent.Gate
local buttonsound = script.Parent.Sound

moving = false
open = false

function onClick(player)
  if player.Team.Name == "CTA" then
	if open == false and moving == false then
        buttonsound:Play()
		moving = true
		trigger.BrickColor = BrickColor.new("Bright yellow")

		for i = 1, (gate.Size.Y * 10 + 1) do
			wait()
			gate.CFrame = gate.CFrame*CFrame.new(0, 0, -0.2)
		end
	
		moving = false
		open = true
		trigger.BrickColor = BrickColor.new("Bright red")

		elseif open == true and moving == false then
		buttonsound:Play()
		moving = true
		trigger.BrickColor = BrickColor.new("Bright yellow")
		
		for i = 1, (gate.Size.Y * 10 + 1) do
			wait()
			gate.CFrame = gate.CFrame*CFrame.new(0, 0, 0.2)
		end
	
		moving = false
		open = false
		trigger.BrickColor = BrickColor.new("Bright green")

	end

end

	script.Parent.ClickDetector.MouseClick:connect(onClick(player))
end

And here’s the base script:

local trigger = script.Parent
local gate = script.Parent.Parent.Gate
local buttonsound = script.Parent.Sound

moving = false
open = false

function onClick(player)
	if open == false and moving == false then
        buttonsound:Play()
		moving = true
		trigger.BrickColor = BrickColor.new("Bright yellow")

		for i = 1, (gate.Size.Y * 10 + 1) do
			wait()
			gate.CFrame = gate.CFrame*CFrame.new(0, 0, -0.2)
		end
	
		moving = false
		open = true
		trigger.BrickColor = BrickColor.new("Bright red")

		elseif open == true and moving == false then
		buttonsound:Play()
		moving = true
		trigger.BrickColor = BrickColor.new("Bright yellow")
		
		for i = 1, (gate.Size.Y * 10 + 1) do
			wait()
			gate.CFrame = gate.CFrame*CFrame.new(0, 0, 0.2)
		end
	
		moving = false
		open = false
		trigger.BrickColor = BrickColor.new("Bright green")

	end

end

script.Parent.ClickDetector.MouseClick:connect(onClick)

And here is how it looks in Workspace.

I honestly just want to know where I need to check the player’s team.
Thanks.

Where you are opening the game, check their using Player.Team

1 Like

In the script you tried, this line should be outside of the function OnClick()

	script.Parent.ClickDetector.MouseClick:connect(onClick(player))
1 Like

What do you mean by “outside” specifically?

(This is the end of your script that you tried)

Move this line:

script.Parent.ClickDetector.MouseClick:connect(onClick(player))

so it will be on the bottom of your script

That line makes it so this line is inside of the function (and you don’t want that). You can’t trigger a function from the inside of it.

1 Like

Oh… and I’m pretty sure you don’t need to use player in that line

1 Like

If I remove the “player” it underlines “onClick” red

“Expected ‘end’ (to close function at line 8), got , did you forget to close ‘do’ at line 29?”

PS: It is at the end of the script, and I removed the end at the bottom, doesn’t work

Make sure it’s like this:

script.Parent.ClickDetector.MouseClick:connect(onClick())
1 Like

I forgot another “end” at the end of the function!

Works perfectly fine now!
Thanks for your noob-friendly assistance :smiley:

You are always welcome, my man! :slight_smile:

1 Like

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