Help with "If [blank] is less than [blank] then" statements

I’m not exactly sure how WaitForChild works, but would I do:

local Player = game.Players.LocalPlayer

Player:WaitForChild(leaderstats,Year_Joined.Value)

if Player.leaderstats.Year_Joined.Value >= 2016 then
game.Workspace.TwentySixteenDoor.Transparency = 1
game.Workspace.TwentySixteenDoor.CanCollide = false
end

(Sorry I keep changing the equals sign and the less than sign, I was experimenting with it and forgot to change it back to less than after I was done.)

Why do I need to detect .Changed? If I needed to do this, where would I do it? In what script?

Create the Year_Joined object as a NumberValue. That should clean up your number comparison problem. If the problem persists, then give time for the leaderboard to load.

leaderstats:WaitForChild("Year_Joined", *)

“*” is for the optional timeout value. (How long to wait before giving up. You don’t actually have to put a comma and timeout number after the first argument. It would just wait infinitely)

1 Like

Okay, so I should do something like this?

Player.leaderstats:WaitForChild("Year_Joined")

Yes, it would wait infinitely for Year_Joined to be created. Make sure it gets created.

1 Like

Okay, here is my script now:

local Player = game.Players.LocalPlayer
Player.leaderstats:WaitForChild("Year_Joined")
if Player.leaderstats.Year_Joined.Value >= 2016 then
game.Workspace.TwentySixteenDoor.Transparency = 1
game.Workspace.TwentySixteenDoor.CanCollide = false
end

I’m not getting any errors and still the script won’t do anything.

local Player = game.Players.LocalPlayer
Player.leaderstats:WaitForChild("Year_Joined")
print("Year value: ", Player.leaderstats.Year_Joined.Value)
if Player.leaderstats.Year_Joined.Value >= 2016 then
    print("Passed")
    game.Workspace.TwentySixteenDoor.Transparency = 1
    game.Workspace.TwentySixteenDoor.CanCollide = false
end

Check if you get both prints. If not, what are you getting from the “Year value” print?

Oddly enough, neither of them printed.

Add print("Test1") under local Player = game.Players.LocalPlayer and print("Test2") right under Player.leaderstats:WaitForChild("Year_Joined")

If that doesn’t work. Double check your script isn’t disabled?

If none of the above print, move your script into the StarterPack and check what results you get. If it’s the same result, then it’s a different issue.

1 Like

It printed Test1, but nothing else.

Change Player.leaderstats:WaitForChild("Year_Joined")
To Player:WaitForChild("leaderstats"):WaitForChild("Year_Joined")

1 Like

It still didn’t work, no matter what I did.

Place the script in the StarterPack just to test if you get the same results.

1 Like

It improved. I got errors:


I have no clue how to fix it though

If your server is creating the Year_Joined value. Make it create a NumberValue instead of a StringValue. Then in code, do the following:

Year_Joined.Value == 2016

The only problem with placing this script in the starterpack is that it will fire everytime the player character respawns. Consider creating a RemoteEvent that will fire once the player joins. After the loaderboard is created, fire an event to the player and have the event modify the door locally.

1 Like

It works now! Thanks so much, @Exeplex! I’ll look into RemoteEvents (because I don’t know much about how to use them).

2 Likes

No problem, please mark the post as the solution for others to see.

Good luck!

1 Like

Also, one final remark.

Don’t take my word for it. I’m pretty sure PlayerStarterScripts has a limited time until it stops executing the scripts within the folder. Maybe there’s not enough time before the leaderboard is created? I’m not sure.

2 Likes