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

How do I make a button only function if player is a certain rank in a group?

local button = script.Parent
local model = game.ReplicatedStorage.tie
local backup = model:Clone()
local nAccess = script.Parent.Parent.Parent.NilAccess
local access = nil

if game.Players.LocalPlayer:GetRankInGroup(13987544) <= 255 then access = true
elseif game.Players.LocalPlayer:GetRankInGroup(13987544) == 0 then access = false
	

	script.Parent.MouseButton1Click:Connect(function()
		if access == true then
		wait(2)
		model = backup:Clone()
		model.Parent = game.Workspace
		model:MakeJoints()
			
			
		elseif access ==  false then
			nAccess.Visible = true
			wait(2)
			nAccess.Visible = false
			
		end
		
	end)
end	
	

I have made a few edits but it still isn't working

Alright, my code may be a bit messy but I'm still fairly new to lua. I want this button to clone a model only if they are a certain rank in said group but display a GUI that says they don't have access if they aren't in said group. This doesn't display any errors and doesn't clone any model; but the no access GUI didn't pop up. How could I do that?

3 comments

0

Your function is inside the block created by your elseif on line 8. Which means it will only run if the player's Rank is equal to 0. Either move your funtion down or move the "if"'s inside the function.

0

It depends on if you want to check the player's rank only when the script first runs or every time they click the button. You should also consider adding a debounce as this button can be clicked multiple times.

0

BTW this can easily be bypassed with exploits.

1 answer

local button = script.Parent
local model = game.ReplicatedStorage:WaitForChild("tie")
local backup = model:Clone()
local nAccess = script.Parent.Parent.Parent.NilAccess
local access = nil

if game.Players.LocalPlayer:GetRankInGroup(13987544) <= 255 then 
	access = true
elseif game.Players.LocalPlayer:GetRankInGroup(13987544) == 0 then 
	access = false    
end

script.Parent.MouseButton1Click:Connect(function()
	if access then --In Lua you can just pass a bool and if it's true it will complete the `if`
	        wait(2)
	        model = model:Clone()
	        model.Parent = game.Workspace
	        model:MakeJoints()
	elseif access ==  false then
		nAccess.Visible = true
		wait(2)
		nAccess.Visible = false
	end
end)

I mainly just changed where the event listener was. In the first script, you created the event listener only if they didn't have access to the group. This means if they did have access to the group the event listener wouldn't be there and they wouldn't be able to press the button. I'm assuming NilAccess is a Frame so the .Visible property would stay the same but if NilAccess is a ScreenGui object (the little white box in a blue box) then you should change the .Visible in the elseif to Enabled. If this did fix the problem please mark it as the answer. I hope this did help! Good Luck

1 comment

0

Now this clones the model even if they're not in the group.

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