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

Data Store script is giving the error "Argument 2 missing or nil"?

Asked by 7 years ago
Edited 7 years ago

I'm trying to make a script that stores the value "Cash" in my script for a sword fighting game. I'm getting the error above on line 15 and I have no idea how to fix it since I got assistance from a YouTube tutorial on how to make this. If anyone could help that would be great.

local maxlevel = 25

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local level = leaderstats:WaitForChild("Level")
    local xp = leaderstats:WaitForChild("XP")

    while wait() do
        local levelvalue = level.Value
        local xpneeded = ((levelvalue * 2) - 1) * 50
        if level.Value < maxlevel then
            if xp.Value >= xpneeded then
                level.Value = level.Value + 1
                xp.Value = xp.Value - xpneeded
            end
        end
    end
end)
0
when you SetAsync, it takes a key as the first parameter and a variant as the second parameter RockerCaleb1234 282 — 7y
0
do i not have that? mrsbigballz 8 — 7y
0
One of your errors is having a period instead of a comma separating those 2 arguments in each SetAsync RockerCaleb1234 282 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

Use this if you are making a save cash

Script in workspace

local DataStore = game:GetService("DataStoreService"):GetDataStore("greatneil80")


game.Players.PlayerAdded:connect(function(player)
    local plr = game.Players.LocalPlayer

    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local Gold = Instance.new("IntValue", stats)
    Gold.Name = "Cash"
    local key = "player-"..player.userId



    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        --Save format: {points, coins}
        Gold.Value = savedValues[1]
    else
        local valuesToSave = {Gold.Value}
        DataStore:SetAsync(key, valuesToSave)
    end


end)

then when player leaves... new script in workspace.....

local DataStore = game:GetService("DataStoreService"):GetDataStore("greatneil80")

game.Players.PlayerRemoving:connect(function(player)

    local key = "player-"..player.userId

    --Save key: {points, coins}
    local valuesToSave = {player.leaderstats.Cash.Value}
    DataStore:SetAsync(key, valuesToSave)

end)

This should work... Have fun..

Ad

Answer this question