So im trying to make an effect when a part touches the ground however i keep getting this error "Workspace.Ball.Script:8: attempt to index a nil value"
script.Parent.Touched:Connect(function(hit) wait(1) game.Workspace.Ball:Clone().Parent = game.Workspace if hit.Parent.Name == 'Balls' then game.Workspace.Ball:Remove().Parent = game.Workspace --effects go here elseif hit.Parent.Name ~= nil then game.Workspace.Ball:Remove().Parent = game.Workspace --effects go here end end)
You're getting that error because the :Remove()
function has no return value, and you tried to index it as if there were a return value. I think you meant to clone the object and not remove it. However if you need to remove an object use :Destroy()
as :Remove()
is deprecated.
script.Parent.Touched:Connect(function(hit) wait(1) -- game.Workspace.Ball:Clone().Parent = game.Workspace if hit.Parent.Name == 'Balls' then game.Workspace.Ball:Clone().Parent = game.Workspace --effects go here end end)