I’m trying to make a mop script that cleans a puddle by using raycasting but it always errors in the output: Unable to cast value to Object.
Can someone explain to me why this is happening?
Here’s my script:
local Tool = script.Parent
local MopRaycast = Ray.new(Tool.CleaningPart.Position,Tool.CleaningPart.Position + Vector3.new(0,3.5,0))
CanClean = false
while wait(1) do
if CanClean == true then
local position, hit = workspace:FindPartOnRay(MopRaycast,{Tool.Handle},false,true)
if hit then
if hit.Name == "Puddle" then
local Health = hit:FindFirstChild("Health")
Health.Value = Health.Value - 1
end
end
end
end