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

Why wont this disable the textbox if player rank is high enough?

server script:

game.Players.PlayerAdded:Connect(function(plr)
	if plr:WaitForChild("leaderstats").Rank.Value >= 5 then
		print("leaderstats")
		script.Parent.SurfaceGui.Enabled = false
	end
end)

no output my rank is over 10k

2 answers

The Problem is at line 2

if plr:WaitForChild("leaderstats").Rank.Value >= 5 then

Don't use :WaitForChild()

Do this

repeat wait() until plr:FindFirstChild("leaderstats")
local leaderstats = plr.leaderstats

This will wait until player have leaderstats

Now put it in your script. It will be like this

game.Players.PlayerAdded:Connect(function(plr)
	repeat wait() until plr:FindFirstChild("leaderstats")
	local leaderstats = plr.leaderstats
    if leaderstats.Rank.Value >= 5 then
        print("leaderstats")
        script.Parent.SurfaceGui.Enabled = false
    end
end)

During times like these the print function is useful. before checking, print the value of their rank. Then that narrows it down to the type of problem you are having. The script is most likely finding the value of rank to be below 5. It is probably the default. I'm assuming you are loading this in with a script somewhere else. This script may be checking their rank before the player's rank is loaded in. Try adding a 0.5 second wait block before the check. You could also just to see this, print when the data has been loaded, and then print when the script is checking. The script that is checking will probably print first without a wait block. If you are not loading in the data. Just changing your rank after loading into the game won't work, because this script is only running once. If you want this script to keep running, put the code (except the game.Players.PlayerAdded) in a while loop

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