"-- Boat Chest Collector Script -- Handles boat movement, chest collection logic, and boat construction
local Players = game:GetService("Players") local Workspace = game:GetService("Workspace") local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Clean workspace Workspace.Enemy:ClearAllChildren() Workspace.Effects:ClearAllChildren() Workspace.Map.Weather:ClearAllChildren() Workspace.Map.SeaContent:ClearAllChildren()
-- Initialize variables local ChestCount = 0 local boatName = player.Name .. "Boat" local boatCenter = Workspace.Boats[boatName].Center local sailV = boatCenter.SailV local teleporting = false
-- Function to build the boat structure local function buildBoat() local boat = Workspace.Boats:FindFirstChild(boatName) if not boat then return end
local deck = boat:FindFirstChild("Deck")
local keel = boat:FindFirstChild("Picture2")
if not deck or not keel then return end
local function createPart(offset)
local part = Instance.new("Part")
part.Name = tostring(#boat:GetChildren() + 1)
part.Size = Vector3.new(1, 1, 1)
part.Anchored = false
part.CanCollide = false
part.CFrame = CFrame.new(deck.Position) *
CFrame.Angles(
math.rad(keel.Orientation.X),
math.rad(keel.Orientation.Y),
math.rad(keel.Orientation.Z)
) *
CFrame.new(offset)
part.Parent = boat
local weld = Instance.new("WeldConstraint")
weld.Part0 = part
weld.Part1 = deck
weld.Parent = part
end
-- Right side parts
for i = -40, 30, 5 do
createPart(Vector3.new(10, 3, i))
end
-- Middle parts
for i = -40, 45, 5 do
createPart(Vector3.new(0, 3, i))
end
-- Left side parts
for i = -40, 30, 5 do
createPart(Vector3.new(-10, 3, i))
end
local deck = boat:FindFirstChild("Deck")
local keel = boat:FindFirstChild("Picture2")
if not deck or not keel then return end
local function createPart(offset)
local part = Instance.new("Part")
part.Name = tostring(#boat:GetChildren() + 1)
part.Size = Vector3.new(1, 1, 1)
part.Anchored = false
part.CanCollide = false
part.CFrame = CFrame.new(deck.Position) *
CFrame.Angles(
math.rad(keel.Orientation.X),
math.rad(keel.Orientation.Y),
math.rad(keel.Orientation.Z)
) *
CFrame.new(offset)
part.Parent = boat
local weld = Instance.new("WeldConstraint")
weld.Part0 = part
weld.Part1 = deck
weld.Parent = part
end
-- Right side parts
for i = -40, 30, 5 do
createPart(Vector3.new(10, 3, i))
end
-- Middle parts
for i = -40, 45, 5 do
createPart(Vector3.new(0, 3, i))
end
-- Left side parts
for i = -40, 30, 5 do
createPart(Vector3.new(-10, 3, i))
end
end
-- Function to weld player to boat local function weldPlayerToBoat() local weld = Instance.new("WeldConstraint") weld.Part0 = humanoidRootPart weld.Part1 = boatCenter weld.Parent = humanoidRootPart humanoidRootPart.CFrame = boatCenter.CFrame * CFrame.new(0, 30, 0) return weld end
-- Function to unweld player local function unweldPlayer(weld) if weld then weld:Destroy() end end
-- Function to teleport player to position with speed local function teleportWithSpeed(destination, speed) teleporting = true local distance = (humanoidRootPart.Position - destination.Position).Magnitude local travelTime = distance / speed
if travelTime > 0 then
wait(travelTime)
end
humanoidRootPart.CFrame = destination.CFrame
teleporting = false
if travelTime > 0 then
wait(travelTime)
end
humanoidRootPart.CFrame = destination.CFrame
teleporting = false
end
-- Function to find nearest chest local function findNearestChest() local chests = Workspace.Map.Temporary:GetChildren() local nearestChest = nil local minDistance = 3000
for _, chest in ipairs(chests) do
if chest.Name == "Dark Sealed Chest" then
local distance = (humanoidRootPart.Position - chest.Position).Magnitude
if distance <= 3000 and distance < minDistance then
nearestChest = chest
minDistance = distance
end
end
end
return nearestChest
for _, chest in ipairs(chests) do
if chest.Name == "Dark Sealed Chest" then
local distance = (humanoidRootPart.Position - chest.Position).Magnitude
if distance <= 3000 and distance < minDistance then
nearestChest = chest
minDistance = distance
end
end
end
return nearestChest
end
-- Function to collect chest local function collectChest(chest) sailV.Velocity = Vector3.new(0, 0, 0) local weld = humanoidRootPart:FindFirstChildOfClass("WeldConstraint") unweldPlayer(weld) teleportWithSpeed(chest, 300)
local args = {
"Carry",
chest
}
ReplicatedStorage.RS.Remote.Misc.Carry:FireServer(unpack(args))
chest.Name = "None"
ChestCount = ChestCount + 1
wait(1)
local args = {
"Carry",
chest
}
ReplicatedStorage.RS.Remote.Misc.Carry:FireServer(unpack(args))
chest.Name = "None"
ChestCount = ChestCount + 1
wait(1)
end
-- Function to place chest local function placeChest() local destination = Workspace.Boats[boatName]["1"] teleportWithSpeed(destination, 300) humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, destination.Position) wait(0.5)
local args = {
"Place"
}
ReplicatedStorage.RS.Remote.Misc.Carry:FireServer(unpack(args))
wait(1)
local args = {
"Place"
}
ReplicatedStorage.RS.Remote.Misc.Carry:FireServer(unpack(args))
wait(1)
end
-- Main loop local function mainLoop() buildBoat() local weld = weldPlayerToBoat() sailV.Velocity = Vector3.new(-300, 0, 0)
while true do
if not teleporting then
if ChestCount == 2 then
placeChest()
ChestCount = 0
else
local chest = findNearestChest()
if chest then
collectChest(chest)
else
teleportWithSpeed(boatCenter, math.huge)
weld = weldPlayerToBoat()
sailV.Velocity = Vector3.new(-300, 0, 0)
end
end
end
wait(0.1)
end
while true do
if not teleporting then
if ChestCount == 2 then
placeChest()
ChestCount = 0
else
local chest = findNearestChest()
if chest then
collectChest(chest)
else
teleportWithSpeed(boatCenter, math.huge)
weld = weldPlayerToBoat()
sailV.Velocity = Vector3.new(-300, 0, 0)
end
end
end
wait(0.1)
end
end
-- Start the script mainLoop()*_