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

Button only pressable by a specific team not working?

I am working on an SCP game, and I am making an admin event that is only pressable by admins. The script I have will not work, here is the script:

function onClick(click)
local group = script.Parent.Parent.Parent
if click.TeamColor == BrickColor.new("Lime green") then
	
	
	local GasPart = game.Workspace.LCZdecon
	local doubleparent = script.Parent.Parent
	--Sounds
	doubleparent.min1:Play()
	wait(30)
	doubleparent.sec30:Play()
	wait(38)
	doubleparent.Begun:Play()
	--Gas and killpart
	GasPart.Part1.Smoke.Enabled = true
	GasPart.Part2.Smoke.Enabled = true
	GasPart.Part3.Smoke.Enabled = true
	GasPart.Part4.Smoke.Enabled = true
	GasPart.Part5.Smoke.Enabled = true
	GasPart.Part6.Smoke.Enabled = true
	GasPart.Part7.Smoke.Enabled = true
	GasPart.Part8.Smoke.Enabled = true
	GasPart.Part9.Smoke.Enabled = true
	GasPart.Part10.Smoke.Enabled = true
	GasPart.Part11.Smoke.Enabled = true
	GasPart.Part12.Smoke.Enabled = true
	GasPart.Part13.Smoke.Enabled = true
	GasPart.Part14.Smoke.Enabled = true
	GasPart.KillPart.Script.Disabled = false
	GasPart.KillPart.CanTouch = true

	print("Decontamination Engaged by admin")
else
	print("Unauthorized player attempted to activate decontamination.")
end

end

script.Parent.MouseClick:Connect(onClick)

If anyone can help I would appreciate it.

2 answers

script.Parent.ClickDetector.MouseClick:Connect(function(plr)

		    if plr.TeamColor == BrickColor.new("Lime green")   then
 print("TEAM COLOR IS REALLY BLACK")
			  
	
local GasPart = game.Workspace.LCZdecon
local doubleparent = script.Parent.Parent
--Sounds
doubleparent.min1:Play()
wait(30)
doubleparent.sec30:Play()
wait(38)
doubleparent.Begun:Play()
--Gas and killpart
GasPart.Part1.Smoke.Enabled = true
GasPart.Part2.Smoke.Enabled = true
GasPart.Part3.Smoke.Enabled = true
GasPart.Part4.Smoke.Enabled = true
GasPart.Part5.Smoke.Enabled = true
GasPart.Part6.Smoke.Enabled = true
GasPart.Part7.Smoke.Enabled = true
GasPart.Part8.Smoke.Enabled = true
GasPart.Part9.Smoke.Enabled = true
GasPart.Part10.Smoke.Enabled = true
GasPart.Part11.Smoke.Enabled = true
GasPart.Part12.Smoke.Enabled = true
GasPart.Part13.Smoke.Enabled = true
GasPart.Part14.Smoke.Enabled = true
GasPart.KillPart.Script.Disabled = false
GasPart.KillPart.CanTouch = true
	
end

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

this is the code that worked for me

script.Parent.ClickDetector.MouseClick:Connect(function(plr)

	if plr.TeamColor == BrickColor.new("Really black")	 then
		print("TEAM COLOR IS REALLY BLACK")
	end
	
	
end)

edit:

also to make it easier you can change:

GasPart.Part1.Smoke.Enabled = true
    GasPart.Part2.Smoke.Enabled = true
    GasPart.Part3.Smoke.Enabled = true
    GasPart.Part4.Smoke.Enabled = true
    GasPart.Part5.Smoke.Enabled = true
    GasPart.Part6.Smoke.Enabled = true
    GasPart.Part7.Smoke.Enabled = true
    GasPart.Part8.Smoke.Enabled = true
    GasPart.Part9.Smoke.Enabled = true
    GasPart.Part10.Smoke.Enabled = true
    GasPart.Part11.Smoke.Enabled = true
    GasPart.Part12.Smoke.Enabled = true
    GasPart.Part13.Smoke.Enabled = true
    GasPart.Part14.Smoke.Enabled = true

to this instead:

for i = 1,14 do
GasPart["Part"..i].Smoke.Enabled = true

end

This makes you write less code since the difference between each line is the number after "Part" which is quite predictable as it is a pattern(starts at 1 and goes up by 1 each time till 14)

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