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

My group rank gate isn't working. Anybody know how to help?[Answered]

I am trying to make a group rank gate, that involves a button and a moving gate. The gate scripts works on its own but when I put it in the group rank script it breaks. This is how I have put both of them together for the group id gate. Script:

local groupID = 5090636					--Group ID
local rankNumber = 255					--Role Number
local higherRanksAllowed = true 		--Only works with rank numbers


function myFunction()
	--Do stuff here
local trigger = script.Parent
local gate = script.Parent.Parent.Gate

moving = false
open = false

function onClick()

	if open == false and moving == false then

		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.1, 0)
		end
	
		moving = false
		open = true
		trigger.BrickColor = BrickColor.new("Bright red")

	elseif open == true and moving == false then

		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.1, 0)
		end
	
		moving = false
		open = false
		trigger.BrickColor = BrickColor.new("Bright green")

	end

end
function clicked(player)
	if player:IsInGroup(groupID) then
		if rankNumber ~= nil then 											--Rank Number
			if player:GetRankInGroup(groupID) == rankNumber then
				myFunction()
			elseif player:GetRankInGroup(groupID) > rankNumber and higherRanksAllowed then
				myFunction()
			end
			discontinueScript = true
		elseif roleName ~= nil and not discontinueScript then			
			if player:GetRoleInGroup(groupID) == roleName then
				myFunction()
			end
		else
			error("No valid rank number or role name set!")
		end
	end
end

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

1 answer

✓ Accepted answer

Your problems arised with having a function inside a function. Firstly, you didn't close the myFunction(), which was why it didn't work. Secondly, I personally wouldn't even suggest having this myFunction() the multi-function setup can not work sometimes, so instead of calling myFunction(), instead call onClick.

However, you did call some local variables inside of the myFunction(), so my replacement code defines all those variables in onClick, so that they can be used globally.

Hope this helps :)

local groupID = 4379044                 --Group ID
local rankNumber = 255                  --Role Number
local higherRanksAllowed = true         --Only works with rank numbers
local moving = false
local open = false

function onClick(trigger, gate)--2
print("got into onClick")
local trigger = script.Parent
local gate = script.Parent.Parent.Gate


    if open == false and moving == false then--3
		
        moving = true
        trigger.BrickColor = BrickColor.new("Bright yellow")

        for i = 1, (gate.Size.Y * 10 + 1) do--4
            wait()
            gate.CFrame = gate.CFrame*CFrame.new(0, 0.1, 0)
        end--c4

        moving = false
        open = true
        trigger.BrickColor = BrickColor.new("Bright red")

    elseif open == true and moving == false then

        moving = true
        trigger.BrickColor = BrickColor.new("Bright yellow")

        for i = 1, (gate.Size.Y * 10 + 1) do--5
            wait()
            gate.CFrame = gate.CFrame*CFrame.new(0, -0.1, 0)
        end--c5

        moving = false
        open = false
        trigger.BrickColor = BrickColor.new("Bright green")

    end--c3

end--c2
function clicked(player)
	print("click detected")
    if player:IsInGroup(groupID) then
        if rankNumber ~= nil then                                           --Rank Number
            if player:GetRankInGroup(groupID) == rankNumber then
                onClick()
            elseif player:GetRankInGroup(groupID) > rankNumber and higherRanksAllowed then
                onClick()
            end
            discontinueScript = true
        elseif roleName ~= nil and not discontinueScript then           
            if player:GetRoleInGroup(groupID) == roleName then
                onClick()
            end
        else
            error("No valid rank number or role name set!")
        end
    end
end

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

Please note I changed the group ID, and commented and printed. You may need to change them back.

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