Load.OnServerEvent:Connect(function(Player, Folder)
contents = Store:GetAsync(Player.UserId, contents)
for i,v in ipairs(contents) do
print(v)
end
end)
try this:
Load.OnServerEvent:Connect(function(Player, Folder)
contents = Store:GetAsync(Player.UserId, contents)
for i,v in ipairs(contents) do
print(table.concat(You’re table,", "))
end
end)
I tried that it did not seem to work.
I don’t ever recommend allowing clients to perform DataStore requests based on if they fire a remote. Your remote has no sanity checks or anything and any time a client fires off the remote, you perform a DataStore call. You need to be mindful of DataStore Limits.
Another problem is the general use of GetAsync which is wrong. First, GetAsync only accepts a single parameter which is the key you want to fetch the value of. The second is that you aren’t using pcall, therefore not accounting for potential fetch failures or DataStore outages. You should always be using pcall when it comes to DataStores.
-- Result will be type variant (any valid datatype) if the fetch is successful,
-- or a string if the call errored. Success is a bool describing if the
-- function errored while executing.
local success, result = pcall(function ()
return Store:GetAsync(Player.UserId)
end)
And finally, the generator. It’s not clear how you’re saving data since you haven’t shown that bit of code, but it’s important to be using the right generator when iterating through tables. If you have a dictionary then you should be using pairs to account for arbitrary indices. If it’s an array, then you can continue to use ipairs.
-- Assuming you used the pcall from above
for index, value in pairs(result) do
-- Print accepts varargs and stitches them together. This will
-- be seen in the console as "x = y".
print(index, "=", value)
end
With all that in mind though, this is all useless advice if you don’t provide more information or do your own debugging. There isn’t much help that can be offered when the only words are from the title that you can’t figure out how to get what’s in a table (you iterate through it) and a code sample.
When posting threads to this category, please avoid just posting code in the thread. The title isn’t enough to describe your problem. You should always be as detailed as possible when posting and give information you think would be relevant to the problem you’re facing. If you’re unsure of what would be good to include in a thread, read our category guidelines, it includes some starter questions you can answer. They don’t have to be formatted the same way but you’ll want to aim to answer them in some way while explaining your problem.
Sorry about that.
Save.OnServerEvent:Connect(function(Player, Folder)
Contents = {}
for _ ,v in ipairs(Folder:GetChildren()) do
if v:IsA("Model") then
local saving = true --Wip
local currentModel = {}
print(v.Name)
local x = math.floor(v:GetPrimaryPartCFrame().X)
local y = math.floor(v:GetPrimaryPartCFrame().Y)
local z = math.floor(v:GetPrimaryPartCFrame().Z)
--Lets not get confused
table.insert(currentModel, {x, y ,z, v.Name}) -- Inserting the data for the current model
table.insert(Contents, currentModel) -- We can then insert the current model table into the Contents table.
end
end
Store:SetAsync(Player.UserId, Contents) -- saving the Contents table
end)
Load.OnServerEvent:Connect(function(Player, Folder)
Contents = Store:GetAsync(Player.UserId, Contents)
for i,v in ipairs(Contents) do
print(v)
end
end)
My problem appears to be for the past 10 hours I cant seem to get the items in the table. The reason i’m using remote events is so i don’t have to leave and join. Once this is working i will add it to a player leave/join function and also add the pcalls. But right now I don’t even know if the data is saving to the table. There are no videos at all explaining what to do. I have started working on this around 2 pm its now 12 am, I am really struggling with this save system. Can someone link me to a video or help me out here. I’m really wanting to give up because this is just to hard. There are no errors, when the prints are called it prints a table id and when i press load it prints 1. I dont know what else to do. Please help.
Which table?
Which prints?
What I mean by you need to be as detailed as possible when explaining a problem, because I can’t understand what you mean when you say it like this. However: assuming what I’m thinking is what you meant to say from that last one, it’s because GetAsync returns a table with more tables in it which is why the table id is getting printed. You’ll need to iterate through the value too from Load.
for _, dataSet in ipairs(Contents) do
for _, value in ipairs(dataSet) do
print(value)
end
end
Are you trying to print an object`s name
Then use this
Load.OnServerEvent:Connect(function(Player, Folder)
contents = Store:GetAsync(Player.UserId, contents)
for i,v in ipairs(contents) do
print(v.Name)
end
end)
Im trying to load the object position.
Load.OnServerEvent:Connect(function(Player, Folder)
contents = Store:GetAsync(Player.UserId, contents)
for i,v in ipairs(contents) do
print(v.CFrame)
end
end)
U cant print an object tho
So it prints all the data that was saved now with this code. However, I don’t know how to get the name of the item. The output it gives is (1,-13, 20, “Table”).
Here is the code
Load.OnServerEvent:Connect(function(Player, Folder)
Contents = Store:GetAsync(Player.UserId, Contents)
for _, dataSet in ipairs(Contents) do
for _, value in ipairs(dataSet) do
for _, Items in ipairs(value) do
print(Items)
end
end
end
end)
It print the name of the object right?
Yes “Table”, how do i get that out of a list so i can clone it with the number positions given?
Just wanted to say that you can print an object.
print({ })
print(function() end)
print(Instance.new("Part"))
print(coroutine.create(function() end))
Its not an object, its a string, v.Name is the string im trying to get.
Did you include
This
print(v.CFrame, v.Name)
Yes, Now it appears that I found an error. Yay, the error is 23:01:00.492 - Unable to cast double to CoordinateFrame on Part:SetPrimaryPartCFrame(value[1], value[2], value[3])
Any I tried to change the number but still seems to error.
U did not say .CFrame
Part:SetPrimaryPartCFrame(value[1].CFrame, value[2].CFrame, value[3].CFrame)
Model::SetPrimaryPartCFrame
expects a CFrame. Not 3 individual numbers. Try:
CFrame.new(value[1], value[2], value[3])
I fixed it, i had to do cframe.new thanks for the help guys means a lot