Why is data persistence giving me an error when saving?
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:
01 | game.Players.PlayerAdded:connect( function (player) |
03 | player:WaitForDataReady() |
05 | local userData = Instance.new( "Folder" , player) |
06 | userData.Name = "userData" |
08 | local banData = Instance.new( "Folder" , userData) |
09 | banData.Name = "banData" |
11 | local banReason = Instance.new( "StringValue" , banData) |
12 | banReason.Name = "reason" |
13 | banReason.Value = player:LoadString( "banReason" ) |
17 | game.Players.PlayerRemoving:connect( function (player) |
19 | game.Players [ player ] :SaveString( "banReason" , player.userData.banData.banReason.Value) |
Thanks!