Whenever anything that isn’t a Model, say a Part, is thrown into the lava, the game thinks that it is a Model and errors because it thinks I am trying to destroy the Workspace.
Here is video footage of what happens when I put a part into the lava.
robloxapp-20211009-0002507.wmv (3.2 MB)
Here is a picture of the output:
Here is the script I am using (The “Bucket” is what the lava’s parent):
local Players = game:GetService("Players")
local Lava = script.Parent
local Bucket = Lava.Parent
-- When something touches the lava.
local function onTouched(hit)
local character = Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent == Bucket:GetDescendants() then -- Prevents the lava from destroying the bucket.
return
elseif character then -- If a character falls in, then kill them!
hit.Parent.Humanoid.Health = 0
elseif hit.Parent:IsA("Model") then -- If hit's parent is a model, then don't just destroy hit, but also its parent.
hit.Parent:Destroy()
else
hit:Destroy() -- If hit is not a model, then just destroy it.
end
end
Lava.Touched:Connect(onTouched)