Problem with my saving a island

local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local islandDataStore = DataStoreService:GetDataStore("IslandData")

local function BringPlayer(player, position)
	local character = player.Character
	if character then
		local spawnOffset = Vector3.new(0, 5, 0)
		character:SetPrimaryPartCFrame(CFrame.new(position + spawnOffset))
	end
end

local function CreateBlock(Vector, Type, parent)
	local block = workspace[Type]
	local clone = block:Clone()
	clone.Parent = parent
	clone.Name = "x"
	clone.Position = Vector3.new(Vector)
end

local function HandleClick(block, audio)
	local currentbreak = block:GetAttribute("CurrentBreakPoints")
	local maxbreak = block:GetAttribute("MaxBreakPoints")
	block:SetAttribute("CurrentBreakPoints", currentbreak + 2)
	print(currentbreak)
	if currentbreak >= maxbreak then
		audio:Play()
		local clone = block:Clone()
		clone.Parent = block.Parent.DroppedItems
		block:Destroy()
	else
		audio:Play()
	end
end

local function AddBreak(block, maxbreak)
	local click = Instance.new("ClickDetector")
	click.Parent = block
	click.Name = "Clicker"
	block:SetAttribute("MaxBreakPoints", maxbreak)
	block:SetAttribute("CurrentBreakPoints", 0)
	local BreakAudio = Instance.new("Sound")
	BreakAudio.Parent = block
	BreakAudio.SoundId = "rbxassetid://6496157434"
	BreakAudio.Name = "BreakAudio"
	click.MouseClick:Connect(function()
		HandleClick(block, BreakAudio)
	end)
end

local function SaveIslandData(player, islandData)
	local success, error = pcall(function()
		local jsonString = HttpService:JSONEncode(islandData)
		islandDataStore:SetAsync(tostring(player.UserId), jsonString)
	end)
	if not success then
		warn("Failed to save island data: " .. error)
	end
end

local function LoadIslandData(player)
	local success, jsonString = pcall(function()
		return islandDataStore:GetAsync(tostring(player.UserId))
	end)

	if success and jsonString then
		local islandData = HttpService:JSONDecode(jsonString)
		return islandData
	end
	return nil
end

local function CreateSkyblockIsland(plr)
	local islandData = LoadIslandData(plr)

	if islandData then
		-- The player already has an island, load the data and recreate it.
		if islandData.Island then
			islandData.Island.Parent = workspace.Skyblock
			BringPlayer(plr, islandData.SpawnPoint)
			print("Player " .. plr.Name .. "'s island loaded.")
		else
			warn("Island data for " .. plr.Name .. " does not contain an 'Island' property.")
		end
	else
		-- The player does not have an existing island, create a new one.
		local island = workspace.Skyblock.PlayerCopyIsland:Clone()
		island.Name = plr.Name .. "_skyblock"
		island.Parent = workspace.Skyblock

		local islandData = {
			Island = island,  -- Include the 'Island' property.
			SpawnPoint = island:FindFirstChild("SpawnBlock").Position,
			Blocks = {}
		}
		SaveIslandData(plr, islandData)

		local Folder = island
		local Inside = Folder:GetChildren()

		for _, Search in ipairs(Inside) do
			if Search:IsA("Part") then
				-- For debugging purposes, set a fixed offset to verify the creation logic.
				local offset = Vector3.new(0, 5, 0)
				local newPosition = Search.Position + offset
				Search.CFrame = CFrame.new(newPosition)
				table.insert(islandData.Blocks, {
					Name = Search.Name,
					Position = Search.Position
				})
			end
		end

		BringPlayer(plr, islandData.SpawnPoint)
		print("Spawn Block Found")
	end

	-- Save the island data for the player
	SaveIslandData(plr, islandData)
end

local function DeleteSkyblockIsland(plr)
	local islandData = LoadIslandData(plr)

	if islandData then
		if islandData.Island then
			islandData.Island:Destroy()
			print("Island data loaded for " .. plr.Name)
		else
			warn("Island data for " .. plr.Name .. " does not contain an 'Island' property.")
		end
		SaveIslandData(plr, islandData)
	else
		print("Island data not found for " .. plr.Name)
	end
	print("Island data saved for " .. plr.Name)
end

game.Players.PlayerAdded:Connect(CreateSkyblockIsland)
game.Players.PlayerRemoving:Connect(DeleteSkyblockIsland)

When I join or leave it gives me Island data for Dacatboy_YT does not contain an 'Island' property. in warn text.

1 Like

Have you tried printing out the islandData table or the raw result in the pcall

nope, let me do that

character limit

Island Data:  -  Server - Skyblock:118
  13:54:29.885   ▼  {
                    ["Blocks"] =  ▼  {
                       [1] =  ▶ {...},
                       [2] =  ▶ {...},
                       [3] =  ▶ {...},
                       [4] =  ▶ {...},
                       [5] =  ▶ {...},
                       [6] =  ▶ {...},
                       [7] =  ▶ {...},
                       [8] =  ▶ {...},
                       [9] =  ▶ {...},
                       [10] =  ▶ {...},
                       [11] =  ▶ {...},
                       [12] =  ▶ {...},
                       [13] =  ▶ {...},
                       [14] =  ▶ {...},
                       [15] =  ▶ {...},
                       [16] =  ▶ {...},
                       [17] =  ▶ {...},
                       [18] =  ▶ {...},
                       [19] =  ▶ {...},
                       [20] =  ▶ {...},
                       [21] =  ▶ {...},
                       [22] =  ▶ {...},
                       [23] =  ▶ {...},
                       [24] =  ▶ {...},
                       [25] =  ▶ {...},
                       [26] =  ▶ {...},
                       [27] =  ▶ {...},
                       [28] =  ▶ {...},
                       [29] =  ▶ {...},
                       [30] =  ▶ {...},
                       [31] =  ▶ {...},
                       [32] =  ▶ {...},
                       [33] =  ▶ {...},
                       [34] =  ▶ {...},
                       [35] =  ▶ {...},
                       [36] =  ▶ {...},
                       [37] =  ▶ {...},
                       [38] =  ▶ {...},
                       [39] =  ▶ {...},
                       [40] =  ▶ {...},
                       [41] =  ▶ {...},
                       [42] =  ▶ {...},
                       [43] =  ▶ {...},
                       [44] =  ▶ {...},
                       [45] =  ▶ {...},
                       [46] =  ▶ {...},
                       [47] =  ▶ {...},
                       [48] =  ▶ {...},
                       [49] =  ▶ {...},
                       [50] =  ▶ {...},
                       [51] =  ▶ {...},
                       [52] =  ▶ {...},
                       [53] =  ▶ {...},
                       [54] =  ▶ {...},
                       [55] =  ▶ {...},
                       [56] =  ▶ {...},
                       [57] =  ▶ {...},
                       [58] =  ▶ {...},
                       [59] =  ▶ {...},
                       [60] =  ▶ {...},
                       [61] =  ▶ {...},
                       [62] =  ▶ {...},
                       [63] =  ▶ {...},
                       [64] =  ▶ {...},
                       [65] =  ▶ {...},
                       [66] =  ▶ {...},
                       [67] =  ▶ {...},
                       [68] =  ▶ {...},
                       [69] =  ▶ {...},
                       [70] =  ▶ {...},
                       [71] =  ▶ {...},
                       [72] =  ▶ {...},
                       [73] =  ▶ {...},
                       [74] =  ▶ {...},
                       [75] =  ▶ {...},
                       [76] =  ▶ {...},
                       [77] =  ▶ {...},
                       [78] =  ▶ {...},
                       [79] =  ▶ {...},
                       [80] =  ▶ {...},
                       [81] =  ▶ {...},
                       [82] =  ▶ {...},
                       [83] =  ▶ {...},
                       [84] =  ▶ {...},
                       [85] =  ▶ {...},
                       [86] =  ▶ {...},
                       [87] =  ▶ {...},
                       [88] =  ▶ {...},
                       [89] =  ▶ {...},
                       [90] =  ▶ {...},
                       [91] =  ▶ {...},
                       [92] =  ▶ {...},
                       [93] =  ▶ {...},
                       [94] =  ▶ {...},
                       [95] =  ▶ {...},
                       [96] =  ▶ {...},
                       [97] =  ▶ {...},
                       [98] =  ▶ {...},
                       [99] =  ▶ {...},
                       [100] =  ▶ {...},
                       [101] =  ▶ {...},
                       [102] =  ▶ {...},
                       [103] =  ▶ {...},
                       [104] =  ▶ {...},
                       [105] =  ▶ {...},
                       [106] =  ▶ {...},
                       [107] =  ▶ {...},
                       [108] =  ▶ {...},
                       [109] =  ▶ {...},
                       [110] =  ▶ {...},
                       [111] =  ▶ {...},
                       [112] =  ▶ {...},
                       [113] =  ▶ {...},
                       [114] =  ▶ {...},
                       [115] =  ▶ {...},
                       [116] =  ▶ {...},
                       [117] =  ▶ {...},
                       [118] =  ▶ {...},
                       [119] =  ▶ {...},
                       [120] =  ▶ {...},
                       [121] =  ▶ {...},
                       [122] =  ▶ {...},
                       [123] =  ▶ {...},
                       [124] =  ▶ {...},
                       [125] =  ▶ {...},
                       [126] =  ▶ {...},
                       [127] =  ▶ {...},
                       [128] =  ▶ {...},
                       [129] =  ▶ {...},
                       [130] =  ▶ {...},
                       [131] =  ▶ {...},
                       [132] =  ▶ {...},
                       [133] =  ▶ {...},
                       [134] =  ▶ {...},
                       [135] =  ▶ {...},
                       [136] =  ▶ {...},
                       [137] =  ▶ {...}
                    }
                 }  -  Server - Skyblock:119

All the return the correct blockName they should

1 Like

In the delete skyblock island function print out the island data.

It might be because you doing islandData.Island:Destroy() before you save so maybe switch them around

Like this?

local function DeleteSkyblockIsland(plr)
	local islandData = LoadIslandData(plr)

	if islandData then
		if islandData.Island then
			SaveIslandData(plr, islandData)
			islandData.Island:Destroy()
			print("Island data loaded for " .. plr.Name)
		else
			warn("Island data for " .. plr.Name .. " does not contain an 'Island' property.")
		end
	else
		print("Island data not found for " .. plr.Name)
	end
	print("Island data saved for " .. plr.Name)
end
1 Like

Yes, just to check you should print out the data in the save island function

local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local islandDataStore = DataStoreService:GetDataStore("IslandData")

local function BringPlayer(player, position)
	local character = player.Character
	if character then
		local spawnOffset = Vector3.new(0, 5, 0)
		character:SetPrimaryPartCFrame(CFrame.new(position + spawnOffset))
	end
end

local function CreateBlock(Vector, Type, parent)
	local block = workspace[Type]
	local clone = block:Clone()
	clone.Parent = parent
	clone.Name = "x"
	clone.Position = Vector3.new(Vector)
end

local function HandleClick(block, audio)
	local currentbreak = block:GetAttribute("CurrentBreakPoints")
	local maxbreak = block:GetAttribute("MaxBreakPoints")
	block:SetAttribute("CurrentBreakPoints", currentbreak + 2)
	print(currentbreak)
	if currentbreak >= maxbreak then
		audio:Play()
		local clone = block:Clone()
		clone.Parent = block.Parent.DroppedItems
		block:Destroy()
	else
		audio:Play()
	end
end

local function AddBreak(block, maxbreak)
	local click = Instance.new("ClickDetector")
	click.Parent = block
	click.Name = "Clicker"
	block:SetAttribute("MaxBreakPoints", maxbreak)
	block:SetAttribute("CurrentBreakPoints", 0)
	local BreakAudio = Instance.new("Sound")
	BreakAudio.Parent = block
	BreakAudio.SoundId = "rbxassetid://6496157434"
	BreakAudio.Name = "BreakAudio"
	click.MouseClick:Connect(function()
		HandleClick(block, BreakAudio)
	end)
end

local function SaveIslandData(player, islandData)
	local success, error = pcall(function()
		print("Island Data:")
		print(islandData)
		local jsonString = HttpService:JSONEncode(islandData)
		islandDataStore:SetAsync(tostring(player.UserId), jsonString)
	end)
	if not success then
		warn("Failed to save island data: " .. error)
	end
end

local function LoadIslandData(player)
	local success, jsonString = pcall(function()
		return islandDataStore:GetAsync(tostring(player.UserId))
	end)

	if success and jsonString then
		local islandData = HttpService:JSONDecode(jsonString)
		return islandData
	end
	return nil
end

local function CreateSkyblockIsland(plr)
	local islandData = LoadIslandData(plr)

	if islandData then
		-- The player already has an island, load the data and recreate it.
		if islandData.Island then
			islandData.Island.Parent = workspace.Skyblock
			BringPlayer(plr, islandData.SpawnPoint)
			print("Player " .. plr.Name .. "'s island loaded.")
		else
			warn("Island data for " .. plr.Name .. " does not contain an 'Island' property.")
		end
	else
		-- The player does not have an existing island, create a new one.
		local island = workspace.Skyblock.PlayerCopyIsland:Clone()
		island.Name = plr.Name .. "_skyblock"
		island.Parent = workspace.Skyblock

		islandData = {
			Island = island,
			SpawnPoint = island:FindFirstChild("SpawnBlock").Position,
			Blocks = {}
		}

		local Folder = island
		local Inside = Folder:GetChildren()

		for _, Search in ipairs(Inside) do
			if Search:IsA("Part") then
				-- For debugging purposes, set a fixed offset to verify the creation logic.
				local offset = Vector3.new(0, 5, 0)
				local newPosition = Search.Position + offset
				Search.CFrame = CFrame.new(newPosition)
				table.insert(islandData.Blocks, {
					Name = Search.Name,
					Position = Search.Position
				})
			end
		end

		BringPlayer(plr, islandData.SpawnPoint)
		print("Spawn Block Found")
	end
end

local function DeleteSkyblockIsland(plr)
	local islandData = LoadIslandData(plr)
	if islandData then
		if islandData.Island then
			SaveIslandData(plr, islandData)  -- Save the island data first
			islandData.Island:Destroy()  -- Then destroy the island
			print("Island data loaded for " .. plr.Name)
		else
			warn("Island data for " .. plr.Name .. " does not contain an 'Island' property.")
		end
	else
		print("Island data not found for " .. plr.Name)
	end
	print("Island data saved for " .. plr.Name)
end

game.Players.PlayerAdded:Connect(CreateSkyblockIsland)
game.Players.PlayerRemoving:Connect(DeleteSkyblockIsland)

Island data for Dacatboy_YT does not contain an ‘Island’ property. - Server - Skyblock:85

What did the save island function print?

Same thing as before.

character limit

Ok try saving the island data as a variable as the start so like islandData2 = islandData then send that to the save function

1 Like