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

[SOLVED] attempt to index nil with 'leaderstats'?

Asked by 2 years ago
Edited 2 years ago
script.Parent.Main.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer

    player.leaderstats.Cashl.Value = player.leaderstats.Cashl.Value + 1 -- the error line.
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

literally three seconds later i found out i had "game.Players.LocalPlayer"

here is the fix lol:

-- Normal script:

script.Parent.GiveCash.OnServerEvent:Connect(function()
    local player = script.Parent.Parent.Parent
    local Debounce = false

    if Debounce == false then
        Debounce = true
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
        wait()
        Debounce = false
    end

end)

-- Local script:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.GiveCash:FireServer()
end)

that was because "game.Players.LocalPlayer" is nil to the server.

https://devforum.roblox.com/t/attempt-to-index-nil-with-leaderstats/530935

Ad

Answer this question