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.