Baqir Zaidi
Baqir Zaidi

Reputation: 13

Lua leaderboard in roblox studio

I have my leader board but when i run this it gives me this error:

attempt to index nil with 'leaderstats'


local me = script.Parent

local function GiveMoney(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    
    if hum then 
        local money = player.leaderstats.Money
        money.Value = money.Value + 1 
        me:Destroy()
    end 
end

me.Touched:Connect(GiveMoney)

Upvotes: 0

Views: 193

Answers (2)

S-a-B-a Nightcores
S-a-B-a Nightcores

Reputation: 11

    local money = player.leaderstats.Money

I think you forgot to reference "player" because I can't see player variable anywhere

Upvotes: 0

Piglet
Piglet

Reputation: 28974

local money = player.leaderstats.Money

or more specifically player.leaderstats causes that error. because player is a nil value and indexing nil values is not allowed as it does not make any sense.

Usually Humanoid's parent is a Model, stored as the Player instance's Character property.

Please read the Roblox documentation and search the web to find out how to access leaderboards and players.

Upvotes: 0

Related Questions