Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with leaderstats?

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

✓ Accepted answer

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)

1 comment

0

Thanks.

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

5 comments

0

Lol, so wrong. I am working with a value, not string. Sorry but this is the wrong answer.

0

I'm sooo sorry, you are right!!!

0

So, why did I get down voted again -_-

0

No clue,

0

I never down vote for people.

This discussion is preserved as it was. New answers, comments, and votes are closed.