Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I can't Add the TextBox Value Into the Data Store?

Hey Everyone, I am making a Ban System It somewhat works, When I type the username of a Person, it bans them, and it works fine with data store too. But i am trying to also do the feature, "The Reason of the Ban"

			local banTable = {}
			table.insert(banTable, player.UserId, script.Parent.PanelScript.Panel.Frame.banReason.Text)
			banDatas:SetAsync(player.UserId, banTable)

When I Try to save the data like This, On the DataStore, it's saved as value "dict" and "" (Basically nothing inside)

https://i.imgur.com/EoADJgQ.png

When the player is banned, I want to tell the Banned User, Why He/She was banned for.

1 answer

You clearly aren't using table.insert() correctly, as the parameters are:

table.insert(table, index, value)

Where:

  • table is the table to use.
  • index is the index to insert value into. If you give value but not index (such as table.insert(a, 1)), table.insert() will place the value at index #table + 1.
  • value is the value to insert into index. Only use this if you specify an index.

Given that you are trying to put the ban reason at the index of player.UserId, it won't work because the index will (almost) always be out of bounds. You can, however, use GetPlayerByUserId() or just specify the player's name by using player.Name. In this case, you'd be creating a key of this format:

local banTable = {}
banTable[player.Name] = script.Parent.PanelScript.Panel.Frame.banReason.Text -- Or GetPlayerByUserId(userID).Name in the brackets, but player.Name is more convenient

If you truly desire using the user ID over the player name, you'd just replace player.Name with player.UserId. (If this doesn't work, use tostring().)

5 comments

0

I see what you mean, but the UserId, works fine, I am just having the trouble saving the reason why the User was banned

0

Because table.insert() is assuming you want to place the ban reason at the index value of the user ID. Obviously that index number is out of bounds, so it doesn't work. You're better off creating a key.

0

I did another table.Insert() for the reason now, I have 2 Values on the table, but still the value isn't what I typed as the Reason of the Ban, it's just "" (empty) Do you think you could add me on discord, so you could help me out please? afterlife#7521

0

Hey, I edited the Value for the "Reason" on the DataStore Editor Plugin, and it worked fine, basically I am just saving it wrong somehow, i did 2 table.Insert() i save the Text of the TextBox, but it saved as nothing, I don't get it why!

0

Ok, just use the key format of banTable[player] = banReason. At this point you're overworking yourself.

This discussion is preserved as it was. New answers, comments, and votes are closed.