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)