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

Why is data persistence giving me an error when saving?

Asked by 7 years ago

I am writing a script that bans players from the, while also saving the reason, so it can be displayed to the player, anyway, loading the data goes fine, no errors... but when saving it, it give me this error: ServerScriptService.loadUserData:19: bad argument #2 to '?' (string expected, got Object).

The code that I am using is:

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

    player:WaitForDataReady()

    local userData = Instance.new("Folder", player)
    userData.Name = "userData"

    local banData = Instance.new("Folder", userData)
    banData.Name = "banData"

    local banReason = Instance.new("StringValue", banData)
    banReason.Name = "reason"
    banReason.Value = player:LoadString("banReason")

end)

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

    game.Players[player]:SaveString("banReason", player.userData.banData.banReason.Value)   

end)

Thanks!

1
Don't use data persistance. Use DataStores. They're much better. RubenKan 3615 — 7y

1 answer

Log in to vote
1
Answered by
farrizbb 465 Moderation Voter
7 years ago

bad argument #2 to '?' (string expected, got Object) means you indexed an value with the wrong type.This means that it should either be a string value not an object value or an object value not a string value

Ad

Answer this question