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

I tried to make a leaderstat script, but it won't even make the leaderstat folder. Why?

Asked by 5 years ago

hi. i'm trying to set up a leaderstat script, but for some reason, and as stated in the title, the leaderstat folder itself isn't even being made at all. i've only gotten it to work once, and i have no idea why it's acting up like this. if someone could explain this oddity to me, or point out any mistakes in the code that might be causing it that isn't just "this is deprecated, don't use it", i'd appreciate it. some extra information: i've put it both in workspace and serverscriptservice. neither locations worked.

code:

01wait()
02local DataStore = game:GetService("DataStoreService")
03local ds1 = DataStore:GetDataStore("LevelData")
04 
05game.Players.PlayerAdded:connect(function(player)
06    print("a")
07    local leader = Instance.new("Folder")
08    leader.Parent = player
09    leader.Name = "leaderstats"
10    print("stat")
11    local lvl = Instance.new("DoubleConstrainedValue",leader) --i know this is deprecated, but i still prefer using it.
12    lvl.Name = "Level"
13    lvl.MaxValue = 50
14    lvl.MinValue = 1
15    lvl.Value = ds1:GetAsync(player.UserId) or 1
View all 24 lines...
0
I see no issue lol u should try removing what’s deprecated(idk what’s deprecated in the code lol) St_vnC 330 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Ok, lets try it!

First Step : First of all we need to know how to acces to the Player. And create values inside a folder named "leaderstats".

Example...

1--> Code <--
2 
3game.Players.PlayerAdded:Connect(function(plr)
4    local folder = Instance.new("Folder", plr)
5    folder.Name = "leaderstats" -->You can't change this!
6end
7 
8--> We already added a folder to the player!

We already added a folder, now we can add some values so we can use it like leaderstats. Can be IntValues or StringValues [For ranks].

Second Step : We can learn how to use a DataStore, but... How we acces to the DataStore of a player?

Easy!

1local ds = game:GetService("DataStoreService")
2local moneyDs = ds:GetDataStore("moneyData")

See? Easy, right? We don't need more than 2 lines of code to acces to the DataStore, but now... How we can start creating a correct leaderstats script?

Easy!

Third Step : Enjoy coding! You aways have to enjoy what are you doing! Play some music while you script or even play a game before to be relaxed.

Lets get into the code!

01--> Locals <--
02 
03local ds = game:GetService("DataStoreService")
04local moneyDs = ds:GetDataStore("moneyData")
05 
06--> Code <--
07 
08--> Player added
09game.Players.PlayerAdded:Connect(function(plr)
10        local folder = Instance.new("Folder", plr)
11        folder.Name = "leaderstats" -->You can't change this!
12 
13        local currency = Instance.new("IntValue", folder)
14        currency.Name = "Money"
15        currency.Value = moneyDs:GetAsync(plr.UserId) or 0 -->If the player doesn't have data   already saved he will take the value of 0
View all 30 lines...

That's how we make a leaderstats with DataStore and easily.

To make a Leveling System [Easy]...

01--> Locals <--
02 
03local ds1 = game:GetService("DataStoreService")
04local levelDs = ds1:GetDataStore("levelData")
05local ds2 = game:GetService("DataStoreService")
06local xpDs = ds2:GetDataStore("xpData")
07local ds3 = game:GetService("DataStoreService")
08local rxpDs = ds3:GetDataStore("rpxData")
09 
10--> Code <--
11 
12--> Player added
13game.Players.PlayerAdded:Connect(function(plr)
14        local folder = Instance.new("Folder", plr)
15        folder.Name = "leaderstats" -->You can't change this!
View all 58 lines...

That's all you need to know.

I hope my answer already solve your question. If it did, please accept my answer. That will help me a lot!

Keep scripting!

Ad

Answer this question