Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Error when a part touches the ground?

Asked by
exarlus 72
5 years ago

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)

0
Because you are removing the ball then you are trying to index the `Parent` of the ball then set it EpicMetatableMoment 1444 — 5y
0
Also `Remove` is a deprecated method EpicMetatableMoment 1444 — 5y

1 answer

Log in to vote
4
Answered by 5 years ago

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)


0
yeah i figured i should have used "Destroyed". Thanks! exarlus 72 — 5y
1
:Destroy()* Gey4Jesus69 2705 — 5y
Ad

Answer this question