Still have questions? Join our Discord server and get real time help.
Log in to vote

Why doesnt my rank go up when i click yes?

Asked by 3 months ago

I have a buy rank gui with a yes button among others but when i click yes it says 14:43:34.297 - ServerScriptService.Leaderstats:28: attempt to index upvalue 'stats' (a nil value)

14:43:34.297 - Stack Begin

14:43:34.298 - Script 'ServerScriptService.Leaderstats', Line 28

14:43:34.298 - Stack End idk what this means, someone pls help yes local script:

local rep = game:GetService("ReplicatedStorage")


script.Parent.Visible = false = false

script.Parent.Parent.Rank.Visible = true

--if game:GetService("Players").LocalPlayer.leaderstats.Money.Value >= 50000 and game:GetService("Players").LocalPlayer.Rank.Value == 0 then--i cut this part out because i didnt wanna have to have the money while testing


--end--cut this part out to not have an end error since i cut out the if statement


leaderboard script:


local stats = player:FindFirstChild("leaderstats")

local Key = "Player-ID:" .. player.UserId

local leaderstats ="Folder", player)

leaderstats.Name = "leaderstats"

local Money ="NumberValue", leaderstats)

Money.Name = "Money"


stats.Money.Value = stats.Money.Value + game.Workspace.Base.Seller.seller.ironore1.Value.Value


local Rank ="NumberValue", leaderstats)

Rank.Name = "Rank"


stats.Rank.Value = stats.Rank.Value + 1


this is not the entire script but its enough to understand

I can't read this BlackOrange3343 2397 — 3mo
what? Gameplayer365247v2 551 — 3mo
I think he meant that he can't understand it CjayPlyz 442 — 3mo
Put it in Lua form Creacoz 107 — 3mo
View all comments (3 more)
? this is lua form Gameplayer365247v2 551 — 3mo
Idk if this is relevant, but you're trying to access leaderstats before you actually create the folder. msuperson24 47 — 3mo
no the folder is created before, the leaderstat works i just cant manage to get the numbers in there to go up every time Gameplayer365247v2 551 — 3mo

1 answer

Log in to vote
Answered by 3 months ago

You are finding the stats before it is even created causing it to be 'nil'. Your code is also pretty messy, I suggest you invest time in learning how events work.

My approach would be to create the leaderstats and loading then data in in a PlayerAdded event. Then you would create a RemoteEvent that would rank the person up.

Server Script:

    local stats ='Folder', player)
    stats.Name = 'leaderstats'

    local Rank ='IntValue', stats)
    Rank.Name = 'Rank'

local rankUp ='RemoteEvent', ReplicatedStorage)
rankUp.Name = 'rankUp'
    local Rank = player.leaderstats:FindFirstChild('Rank')
    Rank.Value = Rank.Value + 1

We are creating an event that triggers every time a player is added. When it's added, we are creating a leaderstat folder for it as well as creating a new stat called 'Rank'. This would also be a good place for loading data since you only need to load data upon entering the game. We are then creating a remote event that upon triggering will look for the stat called 'Rank' (the one we created) and changing its value accordingly.

Note: This remote event would be labled as 'exploitable'. Make sure to always do server checks to make it secure.

Client Script:

local rankUp = ReplicatedStorage:WaitForChild('rankUp')

Now that that is done, all the client has to do is trigger the event by :FireServer().


Answer this question