Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error when a part touches the ground?

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)

2 comments

0

Because you are removing the ball then you are trying to index the Parent of the ball then set it

0

Also Remove is a deprecated method

1 answer

✓ Accepted answer

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)


2 comments

0

yeah i figured i should have used "Destroyed". Thanks!

1

:Destroy()*

This discussion is preserved as it was. New answers, comments, and votes are closed.