Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Argument 2 missing or nil?

Asked by 1 month ago
Edited 1 month ago
while true do wait(30)
        local WaitTime = math.random(2,5)
        game.ReplicatedStorage.SaveDataStatus.Value = "Saving Data..."
        for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(255,255,0)
        end
        print("Saving Data...")
        wait(WaitTime)
        print("Successfully Auto Saved Data!")
        PlayerData:SetAsync(playerUserId, data)
        game.ReplicatedStorage.SaveDataStatus.Value = "Successfully Saved Data!"
        for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(85,255,0)
        end
        wait(2)
        game.ReplicatedStorage.SaveDataStatus.Value = ""
        for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(115,115,115)
        end
    end

local data = {
        strength = player.leaderstats.Strength.Value;
        coins = player.Coins.Value;
        gems = player.leaderstats.Gems.Value;
        rebirths = player.leaderstats.Rebirths.Value;
        class = player.leaderstats.Class.Value;
        rank = player.Rank.Value;
        warnings = player.Warnings.Value;
    }
0
the only thing i can see wrong is you're not defining your data variable. Is that defined someplace else? TGazza 360 — 1mo
0
yes Philipceo90 13 — 1mo

1 answer

Log in to vote
0
Answered by 1 month ago
Edited 1 month ago

If you are getting userId, you should do Player.UserId. Otherwise, if PlayerUserId is a variable, then there shouldn't be an error. In this case, you could use a pcall to run this event.

while true do wait(30)
    local WaitTime = math.random(2,5)
    game.ReplicatedStorage.SaveDataStatus.Value = "Saving Data..."
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(255,255,0)
    end
    print("Saving Data...")
    wait(WaitTime)
    repeat
    local success = pcall(function()
        SetAsync(playerUserId, data)
    end)
    until success
    print("Successfully Auto Saved Data!")

    game.ReplicatedStorage.SaveDataStatus.Value = "Successfully Saved Data!"
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(85,255,0)
    end
    wait(2)
    game.ReplicatedStorage.SaveDataStatus.Value = ""
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.SaveDataStatus.SaveMsg.TextColor3 = Color3.fromRGB(115,115,115)
    end
end

Edit: It would help if we knew what the data was

0
it worked when i put the data variable in the while loop Philipceo90 13 — 1mo
Ad

Answer this question