Table.insert() not working

hello, i am trying to make a shop system where if you buy a character it gets added to a datastore so it is saved the next time you play. at first it worked, but then when i changed the datastore name and removed the old datastore, it stopped working (i did not change the code for the datastore, i just renamed it). So when you buy something it is inserted to the end of the Characters table and it prints out the table but it’s only the 2 starter characters in the table, not the characters bought which should be in there. i probably did do something wrong with the code since im not very good with using datastores

Remote.OnServerEvent:Connect(function(player,Function,rename)
	if Function == "AddOwnedCharacter" then
		if sessionData[player.UserId] then
			table.insert(sessionData[player.UserId].Characters,rename)
            print(sessionData[player.UserId].Characters)
		end
	end
end)

Are you sure it isn’t in the table? Use a for loop to see the contents.

And if it isn’t, make sure you named everything right

any run-time errors here?

what does it print?

Double check the client script and make sure you fired the event, and check if the Function in the start is actually “AddOwnedCharacter”

yeah im sure it isnt, because when i buy it in the shop and i try to equip it i cant because it still says ‘Buy’

Then the shop script is wrong, make sure you actually use any function you define and the ifs are correct

i checked that it was the same exact function and it was, also the table wouldnt be printed into the output if it wasnt the same function

wait oh shoot i forgot to make the rename variable the fighter’s name, thanks this fixed it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.