Help with rank door

  1. What do you want to achieve? Keep it simple and clear!
    I need it so if you have Rank2 or above (example: Rank5) the door will open.

  2. What is the issue? Include screenshots / videos if possible!
    I’m new to coding.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Couldn’t find anything to help.

I have a normal script placed into StarterCharacterScripts, its active but not working.

local Player = game.Players.LocalPlayer

local RequiredRank = "Rank2"

local Barrier = workspace:WaitForChild('Rank1_Barrier')

local leaderstats1 = Player:WaitForChild('leaderstats')

rank = script.leaderstats1.Rank

game.Players.PlayerAdded:Connect(function(Player)
	if rank.Value >= RequiredRank then
		Barrier:Destroy()
	end
end)

If anyone could help that would be greatly appreciated :smiley:

1 Like

Remove the PlayerAdded event as you only need the LocalPlayer.

1 Like
local Player = game.Players.LocalPlayer
local rank = Player:WaitForChild('leaderstats'):WaitForChild("Rank")
local RequiredRank = "Rank2"
local Barrier = workspace:WaitForChild('Rank1_Barrier')

--use this if statement inside of a click event or touch event
if rank.Value == RequiredRank then
	Barrier:Destroy()
end

this should work if everything is defined properly.

also you should consider invoking the server with a remote function to do a rank check and if the server returns true, destroy the barrier on the client side.

It didn’t work :frowning: Any other ideas?

what was the issue with it? did it not send over the table?

umm… what does that mean? xD

You are comparing strings with the greater than operator which will not work.

@LaughyDude227 this is how you grab the table from the server using a remote function, also i fixed an error in the above code, so try that again.

--CLIENT

local someTable = remoteFunction:InvokeServer()

if(someTable)then
    --grabbed the dictionary table, now do whatever
end
--SERVER

local someTable = {}

remoteFunction.OnServerInvoke = function()
    return someTable
end

EDIT: @COUNTYL1MITS that wasn’t me but yeah i didn’t notice it, thank you.

The edited script didn’t work still, sorry :confused:

show me the one you used, please.

local Player = game.Players.LocalPlayer
local rank = Player:WaitForChild('leaderstats'):WaitForChild("Rank")
local RequiredRank = "Rank2"
local Barrier = workspace:WaitForChild('Rank1_Barrier')

--use this if statement inside of a click event or touch event
if rank.Value == RequiredRank then
	Barrier:Destroy()
end

issue might be something else, make sure the barrier and rank value exist, also add some prints to see what the rank value equals.

and let me know of anything that is in the output.

Barrier and value exists:
image
image

I got other scripts to show me what the value equals tho.
image

If it helps any, i use a StringValue for the rank system.

Just found the issue. there is an error but i just didn’t see it.


image

I tried fixing it but it didn’t work.

Comparing “Rank1” and “Rank2” will not work in the way that you want it to.
You could either:
Use string.sub to compare the numbers of the Rank leaderstat
or
Turn the leaderstat into a NumberValue and use that.

I’ll use string.sub for this.

Try this:

-- Localscript
local Player = game.Players.LocalPlayer
local RequiredRank = "Rank2"
local Barrier = game.Workspace:WaitForChild("Rank1_Barrier")
local leaderstats1 = Player:WaitForChild("leaderstats")
local Rank = leaderstats1.Rank

local RankNumeral = tonumber(string.sub(5, Rank.Value))
local RequiredRankNumeral = tonumber(string.sub(5, RequiredRank))

if RankNumeral >= RequiredRankNumeral then
Barrier:Destroy()
end

What is a string.sub?

I’m new to scripting. sorry :frowning:

string.sub returns a part of a string that you provide, or a sub of it.
For example:

local Text = "Hello"
print(string.sub(Text, 1,3))

This returns to Hel, because you specified that it starts at the character number 1, and ends at character number 3.

local Text = "Hello"
print(string.sub(Text, 2,3))

This returns to el because you specified to start at character 2, and end at character 3.

local Text = "Hello"
print(string.sub(Text, 1))

This returns Hello because you specified it to start at character 1, and not end anywhere.

You can learn more about string.sub and other string things here

Where should i put the local script?

You can put it wherever a localscript can properly run.

StarterGui will work fine.