Attempt to index nil with Destroy()

Hello Everyone! I have a script here that’s supposed to destroy a block when a proximity prompt is triggered, issue is, it doesn’t get destroyed and the block stays how it is, i also get this error:

The Script:

local NoteRead = game.ReplicatedStorage:FindFirstChild("Values"):WaitForChild("NoteRead")
local SS = game:GetService("SoundService")
local ExclamationMark = script.Parent.Parent.Parent:FindFirstChild("ExclamationPoint")

script.Parent.Triggered:Connect(function(plr)
	local gui = plr.PlayerGui.Note1.Background
	gui:TweenPosition(UDim2.new(0.312, 0,0.109, 0, "Out","Sine",1))
	NoteRead.Value = true
	SS["Game Sounds"]:WaitForChild("ObjectivesPopUp"):Play()
	ExclamationMark:Destroy()
	script.Parent:Destroy()
end)

Let me know if i’m missing something, and why this happens, thank you everyone!

Could you provide a screenshot of the explorer showing the hierarchy where the ExclamationPoint instance is located?

In other words, can you provide a screenshot of the explorer showing the ExclamationPoint instance and the script that is running the provided code?

1 Like

Here’s where the script is located

image

1 Like

the script that’s running the code i provided is the one under the proximityprompt

1 Like

From the provided code, the script should function perfectly fine, it may be the part itself.

Check to see if the point is anchored or cancollide, it may be falling into the void and getting destroyed.

1 Like

the point is anchored, same issue, this is simple code yet I’m so confused.

My last potential thought on why the issue is occurring is through a conflicting script.

Open the find all menu by going to the view tab at the top of the studio window, then selecting the magnifying glass, then type ExclamationPoint to see all areas where it’s used, as another script might be destroying the object or setting it to nil.

If this isn’t the solution, then I’m not sure what is, I’ve tried my best to help.

didn’t do anything unfortunately, thanks for the help though!

Update:

I fixed it! i just had to make it check that the point exists before trying to destroy it.

Glad to hear that you got it to work out in the end!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.