How do I make a door that a player unlocks when they achieve a certain leaderstat?

I want to make a door that the player automatically unlocks when they have a certain amount of a leaderstat. For example, the door will unlock if they have 5 cash. But, I don’t want it to be a purchasable door, I want it to be a door that unlocks automatically when a player has 5 cash and when they run into it it opens. And, if they don’t have 5 cash and run into it, it won’t open.

The way the door works is when a player walks into it, it’s transparency will switch to 1, then go back to say 0.7 after.

If anyone knows how to do this, please respond.

1 Like

Pseudo code:

if leaderstats = greaterthan/equal to 5 then

[script here]
elseif leaderstats = lessthan 5 then
nil

There are a few ways you can go about this, depending on how you’d like to do it.

The first way is to unlock the door if they go near it, which you can achieve using regions/ touched events to detect whenever a player walks near the door. Then, the door checks if it’s a player, gets the players leaderstats folder and checks if the gold Value is higher than the specified amount.

Another way to do this however is to check every time the gold value is updated. This would mean the door would automatically activate once they get the gold needed, but it may be more expensive for the server.

1 Like