Hello! I’ve ran into a roadblock while scripting a boat for my game. I tried using raycasts to detect when the boat is on land, but when defining FilterDescendentsInstances, the output gave me this error:
“Unable to cast value to Objects”
Here’s my code:
local Seat = script.Parent.VehicleSeat
local TurnedOn = script.Parent.Engine.TurnedOn
local OnCD = script.Parent.Engine.On.ClickDetector
local OffCD = script.Parent.Engine.Off.ClickDetector
local params = RaycastParams.new()
params.FilterDescendantsInstances = game.Workspace.Terrain
params.FilterType = Enum.RaycastFilterType.Include
OnCD.MouseClick:Connect(function()
TurnedOn.Value = true
end)
OffCD.MouseClick:Connect(function()
TurnedOn.Value = false
end)
Seat.Changed:Connect(function()
if TurnedOn.Value ~= false then
script.AngularVelocity.AngularVelocity = Vector3.new(0, -1 * Seat.Steer, 0)
script.LinearVelocity.LineVelocity = 50 * Seat.Throttle
print("works")
end
end)
while task.wait() do
local sPos = script.Parent.VehicleSeat.Position + Vector3.new(0,5,0)
local ePos = script.Parent.VehicleSeat.Position + Vector3.new(0,15,0)
local ray = workspace:Raycast(sPos,ePos - sPos, params)
if ray and ray.Material == Enum.Material.Water then
script.AngularVelocity.Enabled = true
script.LinearVelocity.Enabled = true
else
script.AngularVelocity.Enabled = false
script.LinearVelocity.Enabled = false
end
end
Please let me know what I did wrong. I’m thankful for any suggestions or help!
Thanks
PikeEnthusiast