I am done testing, nothing found.
The print does not appear in the output.
It was put inside of the Player Removing function, are you sure it was ran?
yes, I bought a weapon from my alt and then made it leave the game.
Then the game is saving an empty table
local weapons = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
this is most likely your problem, does the inventory get cleared before it gets the children, and if not is there anything inside of it?
I think I know a way to test this. give me a second.
I bought the weapon, and then switched to the server and checked player_data and it was inside of my inventory
Sorry, Iām not sure. You seem to be doing everything correctly from what I can see. I really donāt know. It should be working
Thatās why I thought it was an Roblox issue
Thank you for helping me at least
Should I repost this as an bug report?
anybody???
You cannot identify the problem because you are ignoring the error. pcall
is used to catch errors, in which it returns a bool and a string. However, you arenāt using the returned values, which makes debugging harder. Please utilize the fullness of pcall; do not ignore what it returns because it is VERY important to datastores.
Also, I noticed this line:
dataStores:SetAysnc(player.UserId.."-Weps",weaponsTable)
I am not sure if it is a typo, but itās supposed to be dataStores:SetAsync
.
The problem was that Async was spelt incorrect, I made this game twice and spelt Async incorrect twice
Can you explain how to utilize the fullness of pcall, I am a new scripterā¦
pcall
returns two values: a bool and a string. The bool can be true or false.
If there is an error, it returns false, then the string will consist of the error message. But if there is no error, it will return true and there is no string returned. pcall
can be used like this:
local success,message = pcall(function()
-- stuff
end)
If you notice, there is two variables in one local. This is how you get both returned values in pcall
.
To use the fullness of pcall
, you would check if the bool is true or false. If it is false, then print the message.
local success,message = pcall(function()
error("Test error")
end)
if not success then
print(message)
end
I am a bit confused, how would i use this in my script?
I would suggest saving data as a table as then you wouldnāt have to do multiple GetAsync
as it is a bad idea as thereās a limit to how many times a minute you can use it
the thing is, I donāt exactly know how to do thatā¦
You can do
local data = {}
data[1] = --Data to store
data[2] = --Data to store
after all you have to do is just save the data table.
and to get the data you can just do player_data = dataStore:GetAsync(key)
and then you can just do player_data[1]
to get the data