Hello, I’m making a boat and I want it to be able to go on water, and ice. But it either wont detect the water or wont detect the ice
for i, boat in pairs(script.Parent:GetDescendants()) do
if boat:GetAttribute("Boat") then
local Seat = boat.VehicleSeat
local ray
local canJump = true
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace.Water:GetDescendants()} -- water is a folder with parts that look like water, the actaul water is invisible
local mass = Seat.Parent.Main:GetMass()
Seat.Jump.Force = Vector3.new(0, mass * 50, 0)
Seat.Changed:Connect(function()
Seat.AngularVelocity.AngularVelocity = Vector3.new(0,-1 * Seat.Steer,0)
Seat.LinearVelocity.LineVelocity = Seat.MaxSpeed * Seat.Throttle
if Seat.Occupant then
Seat.Occupant.JumpPower = 0
end
end)
coroutine.wrap(function()
while task.wait() do
if ray then
if Seat.Occupant ~= nil and ray.Material == Enum.Material.Water then
if Seat.Occupant.Jump == true and canJump == true then
canJump = false
Seat.Jump.Force = Vector3.new(0, mass * 300 * (0.5 * Seat.Parent.JumpPower.Value), 0)
task.wait(0.2)
Seat.Jump.Force = Vector3.new(0, mass * 50, 0)
task.wait(1)
canJump = true
end
end
end
end
end)()
coroutine.wrap(function()
while task.wait() do
local sPos = Seat.Position + Vector3.new(0, 5, 0)
local ePos = Seat.Position - Vector3.new(0, 20, 0)
ray = workspace:Raycast(sPos, ePos - sPos, params)
if ray and ray.Material == Enum.Material.Water then
Seat.AngularVelocity.Enabled = true
Seat.LinearVelocity.Enabled = true
else
Seat.AngularVelocity.Enabled = false
Seat.LinearVelocity.Enabled = false
end
end
print(ray)
end)()
end
end