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

Accessing data in leaderstats??

Asked by 4 years ago

Hi i am trying to access data that is being stored in leaderstats by another script.

I have a script that writes Exp as a number value to the leaderstats and that is working ok.

I am then trying to access that number to obtain which rank to assign a play.

it seems to access the leaderstat data but with the value as 2 it should assign my rank as private but it is assigning me corporal for some reason.

It is most likely something simple but i am new to Lua and have pulled information from several scripts to write this.

Any ideas??

01local Players = game:GetService("Players")
02local ExpDataStore = game:GetService("DataStoreService"):GetDataStore("Exp")
03local RankGui = game:GetService("ServerStorage"):WaitForChild("RankGui")
04 
05 
06local function onPlayerAdded(player)
07    local playerKey = "Player_" .. player.UserId
08    local leaderstats = player:WaitForChild('leaderstats')
09    leaderstats.Name = "leaderstats"
10 
11    local myExp
12    local success, err = pcall(function()
13        myExp = ExpDataStore:GetAsync(playerKey)
14    end)
15    if success then
View all 80 lines...

Answer this question