Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Global Stats Is Deprecated?

Asked by 7 years ago

I'm following up with this tutorial: https://www.youtube.com/watch?v=rWbQ0x-Xjj4

and I'm typing exactly what the guy is typing. I know it's outdated. This worked a month ago.

Here's my code

game.Players.PlayerAdded:connect(function(player)

    statistics = Instance.new("IntValue", player)
    stats.name = "leaderstats"

    points = Instance.new("IntValue", stats)
    points.name = "Points"

end)

2 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

You shouldn't be using stats as your variable, you defined it as statistics. Also define them as local variables with the local keyword.

Also, statistics shouldn't be an IntValue. It's 2016; we have Folders for a reason!

1
Hey, I didn't know `leaderstats` could be anything but IntValue. I had to test this real quick. That's good to know. Have an upvote. Link150 1355 — 7y
0
Link's such a loser. User#11440 120 — 7y
0
Thanks! AtomicChocolate 35 — 7y
0
Thanks guys! And if you have any more questions just ask OP! (Or link lol) RemasteredBox 85 — 7y
Ad
Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago
Edited 7 years ago

Global variables should be avoided as much as possible. They aren't "Deprecated", but it is considered bad practice. Firstly because it clutters up the global environment, but also because in Lua, getting or setting a global variable's value is slower than with a local variable.

Also, while unrelated to the question, as RemasteredBox noted, you declared your variable as statistics but you later refer to it as stats. This is a mistake.

Answer this question