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

attempt to index local cashdata (a number value)?

Asked by
Kurcha 33
6 years ago

And no, before you link me to some wack thread, I have read up on each one and none of them have the right solution, for they are completely different matters.

01game.Players.PlayerAdded:Connect(function(plr)
02    local copieddata = script.Data:Clone()
03    copieddata.Parent = plr
04    local data = game:GetService("DataStoreService")
05    local cashdata = data:GetDataStore("Cash")
06        local success, cashdata = pcall(function()
07            return cashdata:GetAsync(plr)
08        end)
09 
10        if success then
11            if cashdata == nil then
12            cashdata:SetAsync(plr, 0)
13            end
14            copieddata.Cash.Value = cashdata
15    end
View all 67 lines...

ERROR AT LINE 52!

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
6 years ago

At line 06, you attempted to define cashdata again as the data in the data store, which in this case is a number. So when you attempted to set the data at line 52, you're actually calling SetAsync on a number. You need to use a different variable name for the variable to not override itself.

01game.Players.PlayerAdded:Connect(function(plr)
02    local copieddata = script.Data:Clone()
03    copieddata.Parent = plr
04    local data = game:GetService("DataStoreService")
05    local cashdata = data:GetDataStore("Cash")
06        local success, cash = pcall(function()
07            return cashdata:GetAsync(plr)
08        end)
09 
10        if success then
11            if cash == nil then
12            cashdata:SetAsync(plr, 0)
13            end
14            copieddata.Cash.Value = cash
15    end
View all 67 lines...
Ad

Answer this question