How to make Ship spawn only on Water

I am trying to make my spawn tool drop a ship when I am near terrain water. Right now you can spawn the ship anywhere you click, so it can go on land. How can I fix this?

Code
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage.Modules

local ShipHandlerMod = require(Modules.Main.Ships)

	
local Tool = script.Parent

local Player = game:GetService("Players"):WaitForChild(Tool.Parent.Parent.Name)

function insert()
	local root = game.ServerStorage.Ships:FindFirstChild(Tool.Name)
	local rat=root:clone()
	rat.Parent=game.workspace
	
	ShipHandlerMod:SetShip(Player,rat)

	local instances = rat:GetChildren()
	if #instances == 0 then 
		rat:Destroy()	return
	end
	
	local t = Tool.Parent.PrimaryPart

	rat:MoveTo(t.Position + t.CFrame.lookVector * 10)
	--rat.Torso.Anchored=false
	rat.HumanoidRootPart.Anchored = false
	Tool:Destroy()

end
local enabled= true
function onActivated()
	if not enabled then
		return
	end

	enabled = false

--wait(1)
Tool.Handle.TextNotify.Text.Text="Spawning Ship)"
	insert()

end
Tool.Activated:Connect(onActivated)



give me a moment ill try and figure out

1 Like

I made a model quickly, a GUI that spawns a brick and if the brick doesnt touch water, it auto-destructs.
Its not perfect

  • put the Ship model into Lighting
  • the Gui into StarterGui

Let me know if it worked with a like or a SolutionShipWater.rbxm (7.4 KB)

1 Like