How do I make a specific team able to use a ClickDetector?

Hello! I made a script that opens a door up, now the script works when you click the ClickDetector, yet I don’t want anyone able to use the ClickDetector…I want a specific team to be able to click it, and make it work.

Slight issue…I don’t know how to make this.

I tried one thing. I tried this;

local plr = game:GetService("Players").LocalPlayer
script.Parent.Button1.ClickDetector.MouseButton1Click:Connect(function()
	if DoorStatus == "Closed" and Debounce == false and plr.TeamColor = "Color" then 

And it didn’t work… :[

I need some help with this, if someone could give me a working version of this, or if you could give me a hint towards the right answer, that’d be great.

Anticipating/patiently waiting on your reply, lcey.

1 Like
local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")
script.Parent.Button1.ClickDetector.MouseButton1Click:Connect(function()
	if DoorStatus == "Closed" and Debounce == false and plr.Team == Teams["TeamName"] then
	end
end)
1 Like

Actually, you can create serverside script, where you will create algorithm like this:

get BadTeam
if Player.Team = BadTeam then
   game:GetService("Workspace").ClickablePart:WaitForChild("ClickDetector").MaxActivationDistance = 0
end

or

get GoodTeam
if Player.Team != GoodTeam then
   game:GetService("Workspace").ClickablePart:WaitForChild("ClickDetector").MaxActivationDistance = 0
end

That’s kind of simple, but I think that it should work.

1 Like

Have the ClickDetector in workspace always set to 0, use a server script to determine players on the correct team, fire an event to the player, where their local script raises the MaxActivationDistance!

1 Like
local teams = game:GetService("Teams")
local team = teams.Team --Team named "Team".
local clickDetector = script.Parent

clickDetector.MouseClick:Connect(function(player)
	if player.Team == team then --This team can use the ClickDetector.
		--Reward player?
	else
		--Kill player?
	end
end)

You’d check the team property of the player that clicked on the ClickDetector instance which resulted in its “MouseClick” event firing.

2 Likes

Thank you! Adding the extra shebang to either kill or reward can help. My question was already answered by an early answerer. I already have a full code setup where if they aren’t that team, it just doesn’t work. I just posted a snippet here where I needed the team part, yet the rest of the code isn’t here. Thank you though! Keep helping people out! Your doing good.

Thank you!! All support is appreciated. Your script looks a bit more complicated than the kind person who answered earlier with a short, & simple code. Yours is a great alternative option if his/hers doesn’t work. Keep doing what your doing, it’s amazing. -lcey

I love you! Thank you so much, you helped me out a lot. My thanks to you as my game works properly as it should. My two other developer friends, aswell as players on the team that keeps being disturbed all thank you.

Agree to disagree: this is a case of never trust the client. This can be exploited.

1 Like

This idea is good but the simpler idea is what @Forummer said.

This would work, and is super simple to code the ServerScript that I am able to do. YET this is a last resort for me due to there being quite a few ways to do it within the script inside of the door model that opens & closes. This would be a last resort because it just yk, is a more complicated than needed. Love you bro, keep going with what your doing. I encourage you to help others in need every chance you get, peace!

1 Like

Thank you for watching out! Didn’t realize…

Alright thank you for watching out, true champ. I will have to go with @iBuzzes version of my script, because to me…it seems easiest.

Yeah click detectors are great because they are difficult to exploit. Not a lot of exploits on them. The client just sees them and when you click on it it will tell the server you clicked. But then the server can decide if it wants to take your click or just ignore your click. In this case it will take the click if the clicker is on the right team.

1 Like

Heya! This script just isn’t working, yet I really like it. Heres my full code for that;

script.Parent.Button2.ClickDetector.MouseClick:Connect(function()
	if DoorStatus == "Closed" and Debounce == false and plr.Team == Teams["Delta Division"] then
		Debounce = true
		Door.Button2.Click:Play()
		DoorMain.Sound:Play()
		Open()
		wait(1)
		DoorStatus = "Opened"
		Debounce = false
	elseif DoorStatus == "Opened" and Debounce == false and plr.Team == Teams["Delta Division"] then
		Debounce = true
		Door.Button2.Click:Play()
		DoorMain.Sound:Play()
		Close()
		wait(1)
		DoorStatus = "Closed"
		Debounce = false
	end
end)

Is the code in a local script? and where is it located?

The script is located inside of the model, and is a Script.
image

I think you need to put the plr in the parameters.

script.Parent.Button2.ClickDetector.MouseClick:Connect(function(plr)
	if DoorStatus == "Closed" and Debounce == false and plr.Team == Teams["Delta Division"] then
		Debounce = true
		Door.Button2.Click:Play()
		DoorMain.Sound:Play()
		Open()
		wait(1)
		DoorStatus = "Opened"
		Debounce = false
	elseif DoorStatus == "Opened" and Debounce == false and plr.Team == Teams["Delta Division"] then
		Debounce = true
		Door.Button2.Click:Play()
		DoorMain.Sound:Play()
		Close()
		wait(1)
		DoorStatus = "Closed"
		Debounce = false
	end
end)

It works! Thank you so much, keep up the good work. I couldn’t figure it out, yet you could. Guess that’s why my role is a modeler, not a scripter. Again, THANK YOU!

Yet actually, sorry for bothering so much…but how would I do multiple teams?