Ad
Log in to vote
0

Error: Attempt to index local 'player' (a number value)?

Asked by 2 months ago
Edited 2 months ago

ServerScriptService.Leaderboard:17: attempt to index local 'player' (a number value)

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local cash = Instance.new("IntValue",folder)
    cash.Name = "Cash"

    cash.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, cash.Value)

    cash.Changed:Connect(function()
        ds1:SetAsync(player.UserId, cash.Value)
    end)
    game.ServerStorage.Give.Event:Connect(function(player,Amount)
        if player.Name == player.Name then
            cash.Value = cash.Value + Amount
        end
    end)
end)

Filtering Enabled on

Script in ServerScriptService

BindableEvent in ServerStorage

BindableEvent rename to Give

I do it a lots of time but it not work.

I script 2 script

1.leaderboard 2.kill for money script

It not give me the Cash when I kill NPC.

I open output and click the only error one.

and it go to the box up there.

Please help.

1 answer

Log in to vote
0
Answered by 2 months ago

Issues

There are a few issues with your code.

Firstly,

you are obviously not parsing the correct arguments. If the script believes that the player is the number, then you obviously have not passed the player as an argument to the event.

Secondly,

the event overrides the player variable in the script, meaning the if statement will always return true, and every person will always receive the cash. Rename the variable on the event arguments to something else to fix this.

Conclusion

So, you just need to check your script which fires the event and rename a variable, and hopefully everything should be working.

If I helped you, remember to mark this as the correct answer and thumbs up. :)

0
Thank, it work but there is a second error but I will not delete this bentri2006 -3 — 2mo
Ad

Answer this question