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

Help with leaderstats?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

I am making stats and I want the owners to have a certain amount of cash. I am having trouble at the bottom of this script. Thanks :)

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

    --// Stats //--

    local folder = Instance.new("Folder",plr)
    folder.Name  = "leaderstats"

    local stat3  = Instance.new("BoolValue",plr)
    stat3.Name   = "HasHome?"
    stat3.Value  = false

    local stat1  = Instance.new("StringValue",folder)
    stat1.Name   = "Cash"
    stat1.Value  = 1000

    local stat2  = Instance.new("StringValue",folder)
    stat2.Name   = "Class"
    stat2.Value  = "Low Class"

    --// Owner's stats //--
    if plr.Name == "PlayersName" or "PlayersName2"  or "PlayersName3" then
        game.Players.PlayersName.leaderstats.Cash = 9999999
        game.Players.PlayersName2.leaderstats.Cash = 9999999
        game.Players.PlayersName3.leaderstats.Cash = 9999999
    end

end)

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

As KingLoneCat pointed out, you should use IntValue or NumberValue to store integers/numbers respectively (not StringValue).


Or

What do you think or does?

or combines to conditions together. For example,

badDayForPicnic = isCold or isRaining

It does not combine values:

fruit = "blueberry" or "strawberry"
print(fruit) --> blueberry

You do not get some "multi-value" which you can compare plr.Name against all of the strings at once.

You must be explicit and repeat your conditions:

if plr.Name == "One" or plr.Name == "Two" or plr.Name == "Three" then

Logic

The logic behind lines 21--25 makes little sense.

When a new player joins, you check their name.

If the new player is a VIP,

You set every VIP's money to a big number.


This is clearly not a reasonable thing to do

  • having your money reset when someone else does something is definitely fishy
    • why is the plr who is joining not involved in this code?
  • if the other VIP's aren't there, the script will just crash because game.Players.VIP2 doesn't exist!

Just modify stat1:

    stat1.Value = 999999

(You had also forgotten your .Value on the cashes)

0
Thanks. FiredDusk 1466 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Problem:

You are using a StringValue for integers which works however, you forgot the quotation marks or however you make a string.

Solution:

Either make the Cash a IntValue by doing the following:

local stat1  = Instance.new("IntValue", folder)
stat1.Name = "Cash"
stat1.Value = 1000

OR..

You can add quotation marks to the StringValues 'cause that's what marks StringValues... Something of this sort:

stats1.Value = "1000"

game.Players.PlayersName.leaderstats.Cash = "99999999"

I hope I helped and thank you for reading this answer.

~~ KingLoneCat

0
Lol, so wrong. I am working with a value, not string. Sorry but this is the wrong answer. FiredDusk 1466 — 8y
0
I'm sooo sorry, you are right!!! FiredDusk 1466 — 8y
0
So, why did I get down voted again -_- KingLoneCat 2642 — 8y
0
No clue, FiredDusk 1466 — 8y
0
I never down vote for people. FiredDusk 1466 — 8y

Answer this question