Accessing data in leaderstats??
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??
01 | local Players = game:GetService( "Players" ) |
02 | local ExpDataStore = game:GetService( "DataStoreService" ):GetDataStore( "Exp" ) |
03 | local RankGui = game:GetService( "ServerStorage" ):WaitForChild( "RankGui" ) |
06 | local function onPlayerAdded(player) |
07 | local playerKey = "Player_" .. player.UserId |
08 | local leaderstats = player:WaitForChild( 'leaderstats' ) |
09 | leaderstats.Name = "leaderstats" |
12 | local success, err = pcall ( function () |
13 | myExp = ExpDataStore:GetAsync(playerKey) |
16 | print ( "Experience Data Found" ) |
21 | local clonedgui = RankGui:Clone() |
22 | clonedgui.TextLabel.Text = "Private" |
23 | clonedgui.TextLabel.TextColor 3 = Color 3. fromRGB( 36 , 154 , 136 ) |
25 | clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head |
29 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
30 | print ( "Lance Corporal" ) |
32 | clonedgui.TextLabel.Text = "Lance Corporal" |
36 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
39 | clonedgui.TextLabel.Text = "Corporal" |
43 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
46 | clonedgui.TextLabel.Text = "Sergeant" |
50 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
51 | print ( "Staff Sergeant" ) |
53 | clonedgui.TextLabel.Text = "Staff Sergeant" |
57 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
58 | print ( "Warrant Officer Class 2" ) |
60 | clonedgui.TextLabel.Text = "WO2" |
64 | local clonedgui = player.Character.Head:FindFirstChild( "RankGui" ) |
65 | print ( "Warrant Officer Class 1" ) |
67 | clonedgui.TextLabel.Text = "WO1" |
74 | leaderstats.Parent = player |
77 | for _, player in pairs (Players:GetPlayers()) do |
80 | Players.PlayerAdded:Connect(onPlayerAdded) |