New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 3 months ago

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

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
3 months ago

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)
Ad
Log in to vote
-1
Answered by
sheepposu 378 Moderation Voter
3 months ago

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

Answer this question