How do i add a group lock to this? (With Module Script)

Hello Developers!

I have a quick question, I have a part with a click detector. Giving the player who clicks on it a GUI. The script is down below:

function onClick(click)
for i,v in pairs (script.Parent:GetChildren()) do
	if v.ClassName == "ScreenGui" then
		a = v:Clone()
		a.Parent = click.PlayerGui
	end
end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

I know how I need to use Module Scripts and I want to use that for the Group and Rank lock, but. I don’t really know how I should adjust the script, nor do I have a feeling this script is good.

I would love to hear it from the audience of the DevForum.

Thanks for reading!

MODULE SCRIPT

local cfg = {

	group = 0, 		-- GROUP ID HERE
	minRank = 0		-- MIN RANK

}

return cfg

SCRIPT

local cfg = require(MODULE SCRIPT PATH)

function onClick(click)
	for i,v in pairs (script.Parent:GetChildren()) do
		if v.ClassName == "ScreenGui" then
			if click:GetRankInGroup(cfg.group) => cfg.minRank then
				a = v:Clone()
				a.Parent = click.PlayerGui
			end
		end
	end
end

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

Also, I would use this video for guidance on how to use ModuleScripts

I used that video to learn Module Scripts a few months ago. But still, thank you!

Do the scripts work?

30charlimit