DataStore object saving doesn't save?
Asked by
4 years ago Edited 4 years ago
Ok, so...Hi.
I have some problems with my Data store...For the 10th time I ever try to save something...
Here's a more detailed explanation of the issue:
Error I get:
ServerScriptService.DataStoreScript:18: attempt to index nil with 'GetChildren'
About the error:
I have a folder that should be looped thru when the player leaves the game. That folder(as I test) has objects inside of it. They ARE in the server and they DO exist, but for some reason the script doesn't see the folder.
Where have I tested the script?
In studio and in game. I don't know about you, but for me the data stores save in studio as long as I have the *API *and *HTTP * on.
What am I trying to even save?
The object's Name, CFrame(made into X, Y, Z and Orientation values)
Got any other questions?
Ask ahead. I will try and answer them as good and detailed as possible.
Tho I hope you don't have because it's kinda late for me now xd (12am) and might not even see them, so if I don't see them you'd loose interest in helping me and forget about this.
Script:
01 | local Players = game.Players |
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local DataStore = DataStoreService:GetDataStore( "PlotSave" ) |
04 | local Plots = game.Workspace.Plots:GetChildren() |
07 | game.Players.PlayerRemoving:Connect( function (player) |
08 | local Key = player.UserId |
12 | for i,v in pairs (Plots) do |
13 | if v.Owner.Value = = player then |
14 | ObjectsFolder = v.PlacedObjects |
18 | for i,v in pairs (ObjectsFolder:GetChildren()) do |
20 | table.insert(SaveTable, |
22 | [ "ObjectName" ] = v.Name, |
24 | [ "X" ] = v.PrimaryPart.CFrame.X, |
25 | [ "Y" ] = v.PrimaryPart.CFrame.Y, |
26 | [ "Z" ] = v.PrimaryPart.CFrame.Z, |
27 | [ "Rotation" ] = v.PrimaryPart.Orientation.Y } |
33 | local Success, ErrorMessage = pcall ( function () |
34 | DataStore:SetAsync(Key, SaveTable) |
37 | print ( "Successfully saved Data" ) |
38 | for i,v in pairs (SaveTable) do |
42 | warn( "Failed to save Data: " .. tostring (ErrorMessage)) |
47 | game.Players.PlayerAdded:Connect( function (player) |
48 | local Key = player.UserId |
52 | for i,v in pairs (Plots) do |
53 | if v.Owner.Value = = player then |
54 | ObjectsFolder = v.PlacedObjects |
58 | local Success, ErrorMessage = pcall ( function () |
59 | SavedPlot = DataStore:GetAsync(Key) |
65 | warn( "Data Failed to be read: " .. tostring (ErrorMessage)) |
70 | print ( "There is a Saved Plot" ) |
71 | for i,v in pairs (SavedPlot) do |
74 | local SavedModel = game.ReplicatedStorage.Objects:FindFirstChild(v.Name):Clone() |
76 | SavedModel:SetPrimaryPartCFrame(CFrame.new(v.ObjectCFrame.X, v.ObjectCFrame.Y, v.ObjectCFrame.Z) * CFrame.Angles( 0 , math.rad(v.ObjectCFrame.Rotation), 0 )) |
77 | SavedModel.Parent = nil |
84 | print ( "No Saved Plot" ) |