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

Attempt to index nil with 'Destroy'?

i'm trying to use a remote event to destroy a basic part, which is a child of the player. here's the code:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local waa = player:FindFirstChild("CloudPower")
	wait()
	waa:Destroy()
end)

2 comments

0

Was the part created in a local script?

0

was the part in a local script? if so then use this script: https://pastebin.com/raw/PzUMF9tn

1 answer

✓ Accepted answer

This error means that the object you're trying to destroy doesn't exist.

I think the issue here might be either that:

  • You're pointing to the wrong path, so the script doesn't see the object,
  • You've instanced (created) the script in a localscript.

The fix is either:

  • Check if the path to the "CloudPower" object is correct,
  • Create "CloudPower" with a serverscript or fire a remotevent in order to create the "CloudPower" object.

Hope I helped!

1 comment

0

yes, it is in a local script! i thought about that earlier. i'll have to move the script that makes the part into the server script

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