Heya everyone. I’ve been working on a Minecraft like building system and mining system. And it’s going really well. And I’m wanting to be able to save the builds that you make to data stores. But for some reason, it’s not working. It doesn’t save (I checked the /console in-game).
So basically, the parts positions that I’m needing to save are put through a for loop and put into a table. The table is then saved to the data store. I’m not super good at data stores, and still get confused by them. But I’m pretty sure that this code is correct.
Once they join, I try to receive the table from the data store, but it always prints “No Data.”
The loading parts code is fine. I checked it myself using a modified script. The problem seems to be with the saving part. I’ve checked the forums and scripting helpers, but can’t find anything on how to fix it.
API services are turned on btw.
Anyway, the game is similar to islands. And you build and place blocks. When blocks are placed they are parented to game.Workspace.Island. And if no data is detected it loads the default island.
(This is also on a server script).
Here’s the code:
local DataStoreService = game:GetService("DataStoreService")
local Update = "1" -- ignore this
local IslandPositionsX = DataStoreService:GetDataStore("IslandBlockPositionsXOne")
local IslandPositionsY = DataStoreService:GetDataStore("IslandBlockPositionsYOne")
local IslandPositionsZ = DataStoreService:GetDataStore("IslandBlockPositionsZOne")
local IslandBlockTypes = DataStoreService:GetDataStore("IslandBlockTypes")
function loadDefaultIsland()
local Island = game.ServerStorage:WaitForChild("DefaultIsland"):Clone()
Island.Name = "Island"
Island.Parent = game.Workspace
end
local function onPlayerJoin (player)
local PlayerIslandsPositionsX = "Player_"..player.UserId.."BlockPositionsX"
local PlayerIslandsPositionsY = "Player_"..player.UserId.."BlockPositionsY"
local PlayerIslandsPositionsZ = "Player_"..player.UserId.."BlockPositionsZ"
local DataX = IslandPositionsX:GetAsync(PlayerIslandsPositionsX)
local DataY = IslandPositionsX:GetAsync(PlayerIslandsPositionsX)
local DataZ = IslandPositionsX:GetAsync(PlayerIslandsPositionsX)
if DataX then
for Number, BlockX in pairs(DataX) do
local ClonedBlock = game.ServerStorage.Blocks.GrassBlock:Clone()
ClonedBlock.Parent = game.Workspace.Island
ClonedBlock.Position = Vector3.new(DataX[Number], DataY[Number], DataZ[Number])
wait()
end
print("Waiting")
wait(1)
print("Destroy")
game.Workspace.TestIsland:Destroy()
print("Destroyed")
else
loadDefaultIsland()
print("No Data")
end
end
local function onPlayerExit(player)
print("Player left")
local Success, ErrorMessage = pcall(function()
local PlayerIslandsPositionsXPassword = "Player_"..player.UserId.."BlockPositionsX"
local PlayerIslandsPositionsYPassword = "Player_"..player.UserId.."BlockPositionsY"
local PlayerIslandsPositionsZPassword = "Player_"..player.UserId.."BlockPositionsZ"
local IslandBlockPositionsX = {}
local IslandBlockPositionsY = {}
local IslandBlockPositionsZ = {}
for Number, Block in pairs(game.Workspace.TestIsland:GetChildren()) do
print("Looping")
table.insert(IslandBlockPositionsX, Block.Position.X)
table.insert(IslandBlockPositionsY, Block.Position.Y)
table.insert(IslandBlockPositionsZ, Block.Position.Z)
wait()
end
print(IslandBlockPositionsX)
print(IslandBlockPositionsY)
print(IslandBlockPositionsZ)
IslandPositionsX:SetAsync(PlayerIslandsPositionsXPassword, IslandBlockPositionsX)
IslandPositionsY:SetAsync(PlayerIslandsPositionsYPassword, IslandBlockPositionsY)
IslandPositionsZ:SetAsync(PlayerIslandsPositionsZPassword, IslandBlockPositionsZ)
end)
if not Success then
warn("Could not save data. Error:"..ErrorMessage)
else
print("Saved")
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
Anyway, if anyone knows how to fix this, any help would be appreciated.
(I don’t know if this is the right category… so yea)
– Jeff 