Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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:

01local Players = game.Players
02local DataStoreService = game:GetService("DataStoreService")
03local DataStore = DataStoreService:GetDataStore("PlotSave")
04local Plots = game.Workspace.Plots:GetChildren()
05 
06 
07game.Players.PlayerRemoving:Connect(function(player)
08    local Key = player.UserId
09    local SaveTable = {}
10    local ObjectsFolder
11 
12    for i,v in pairs(Plots) do
13        if v.Owner.Value == player then
14            ObjectsFolder = v.PlacedObjects
15            break
View all 86 lines...
0
objectsfolder is nil srimmbow 241 — 4y
0
Line 14 should make it not nil bostaffmanbulgaria1 89 — 4y

1 answer

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

when you do local Plots = workspace.Plots:GetChildren() at the start of the script, it only gets the children at that specific time. it doesn't automatically update tables when you add or remove children

of course, when a server first opens and this script runs, nothing is going to be in the Plots folder

you have to get the children of Plots every time you want to save a player's data

1for i,v in pairs(workspace.Plots:GetChildren()) do
2    if v.Owner.Value == player then
3        ObjectsFolder = v.PlacedObjects
4        break
5    end
6end
0
Imma try it out when i got some time, thanks for the help bostaffmanbulgaria1 89 — 4y
Ad

Answer this question