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
5 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.

game.Players.PlayerAdded:Connect(function(plr)
    local copieddata = script.Data:Clone()
    copieddata.Parent = plr
    local data = game:GetService("DataStoreService")
    local cashdata = data:GetDataStore("Cash")
        local success, cashdata = pcall(function()
            return cashdata:GetAsync(plr)
        end)

        if success then
            if cashdata == nil then
            cashdata:SetAsync(plr, 0)
            end
            copieddata.Cash.Value = cashdata
    end


    --data


    local copiedplotinfo = script.PlotInformation:Clone()
    copiedplotinfo.Parent = plr
    if workspace.Plots.Plot1.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot1"
        workspace.Plots.Plot1.Owner.Value = plr.Name
    elseif workspace.Plots.Plot2.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot2"
        workspace.Plots.Plot2.Owner.Value = plr.Name
    elseif workspace.Plots.Plot3.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot3"
        workspace.Plots.Plot3.Owner.Value = plr.Name
    elseif workspace.Plots.Plot4.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot4"
        workspace.Plots.Plot4.Owner.Value = plr.Name
    end
    --plot placement


    local currentplot = copiedplotinfo.Plot.Value
    local plot = workspace.Plots:FindFirstChild(currentplot)
    local function farmincome() --farm gainer stuff
        local farm = plot.Farm
        local farmlvl = farm.LVL.Value
        local income = 0
        if farmlvl == 1 then
            income = 50
        end
        local Cash = copieddata.Cash
        Cash.Value = Cash.Value + income
        print("Gave farm cash respectively. New cash=".. Cash.Value)
        print("Amount of cash recieved=".. income)
        cashdata:SetAsync(plr, Cash.Value)
    end

    local function westernshootoutscoutedition()
        --MAKE SCOUT DELAY TIME AND CASH GAIN ETC
    end

    while true do
        wait(5)
        farmincome() --farm income delay and thing
        wait()
    end

    --next oen here
    --farms, zombie dmg, etc. (active slots r used for like showing if it actually function)
end)

ERROR AT LINE 52!

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
5 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.

game.Players.PlayerAdded:Connect(function(plr)
    local copieddata = script.Data:Clone()
    copieddata.Parent = plr
    local data = game:GetService("DataStoreService")
    local cashdata = data:GetDataStore("Cash")
        local success, cash = pcall(function()
            return cashdata:GetAsync(plr)
        end)

        if success then
            if cash == nil then
            cashdata:SetAsync(plr, 0)
            end
            copieddata.Cash.Value = cash
    end


    --data


    local copiedplotinfo = script.PlotInformation:Clone()
    copiedplotinfo.Parent = plr
    if workspace.Plots.Plot1.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot1"
        workspace.Plots.Plot1.Owner.Value = plr.Name
    elseif workspace.Plots.Plot2.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot2"
        workspace.Plots.Plot2.Owner.Value = plr.Name
    elseif workspace.Plots.Plot3.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot3"
        workspace.Plots.Plot3.Owner.Value = plr.Name
    elseif workspace.Plots.Plot4.Owner.Value == "Nil" then
        copiedplotinfo.Plot.Value = "Plot4"
        workspace.Plots.Plot4.Owner.Value = plr.Name
    end
    --plot placement


    local currentplot = copiedplotinfo.Plot.Value
    local plot = workspace.Plots:FindFirstChild(currentplot)
    local function farmincome() --farm gainer stuff
        local farm = plot.Farm
        local farmlvl = farm.LVL.Value
        local income = 0
        if farmlvl == 1 then
            income = 50
        end
        local Cash = copieddata.Cash
        Cash.Value = Cash.Value + income
        print("Gave farm cash respectively. New cash=".. Cash.Value)
        print("Amount of cash recieved=".. income)
        cashdata:SetAsync(plr, Cash.Value)
    end

    local function westernshootoutscoutedition()
        --MAKE SCOUT DELAY TIME AND CASH GAIN ETC
    end

    while true do
        wait(5)
        farmincome() --farm income delay and thing
        wait()
    end

    --next oen here
    --farms, zombie dmg, etc. (active slots r used for like showing if it actually function)
end)
Ad

Answer this question