SO, I’m trying to make a datastore to save some data for a player using a table, but for some reason I cannot take any values out of the table. It could be something simple that I’m not seeing, but I’ve been stuck on this for a few days. Instead of giving the value, it simply prints “nil”. (When it says print(Slot1))
Code to create the datastore/table:
local DatastoreService = game:GetService("DataStoreService")
local MenuDataStore = DatastoreService:GetDataStore("MenuDataStore")
local data = {
playedbefore = true;
slot1 = false;
slot2 = false;
slot3 = false
}
game.Players.PlayerAdded:Connect(function(plr)
local val = true
while val do
if plr.Character ~= nil then
plr.Character:WaitForChild("HumanoidRootPart").Anchored = true
val = false
end
wait()
end
pcall(function()
if MenuDataStore:GetAsync(plr.UserId) == nil then
--Save player data (only for the starting screen)
MenuDataStore:SetAsync(plr.UserId, data)
end
--Datastore to see if the player has played before, if == nil, then give values
end)
end)
Code to access the datastore/table:
local val1 = true
local plr = script.Parent.Parent.Parent.Parent.Parent
local DatastoreService = game:GetService("DataStoreService")
while val1 do
pcall(function()
if DatastoreService:GetDataStore("MenuDataStore"):GetAsync(plr.UserId) ~= nil then
local MenuDataStore = DatastoreService:GetDataStore("MenuDataStore", data)
local Data = MenuDataStore:GetAsync(plr.UserId, data)
print(Data)
local Slot1 = table.find(Data, slot1)
print(Slot1)
--local Data = MenuDataStore.data:Find(Slot1)
if Slot1 == false then
print("LoadedCorrectly")
end
end
wait()
end)
end
I’m pretty new to using LUA, so please don’t judge ![]()