Is not a valid member of Workspace "Workspace" error with LocalScript

Hello,

So basically I’ve been trying to do it so once you trigger the flashlight ProximityPrompt, the part will be destroyed locally. I’ve been trying all day long to get this to work and things simply won’t work. I initially tried with a more complicated way involving ServerScripts and RemoteEvents and such but it just wasn’t going nowhere. I’m now deciding to just use a LocalScript and see what happens.

Clip of my problem:

Simple stuff, trigger the proximity and the part should destroy locally. Nothing from the other world but since I’m not very experienced in scripting I struggle at times.

How things are set up:

LocalScript inside StarterCharacterScripts
image

The code inside

local proximity = game.Workspace.BasementFlashlight.ProximityPrompt
local barrier = game.Workspace.BasementBarrier

proximity.Triggered:Connect(function(var)
	barrier:Destroy()
end)

I’ve been getting this annoying error the whole day which has been killing me and I assume this is all that’s left that’s preventing things from working.
image

What’s it talking about?? I literally have the BasementFlashlight inside Workspace.

I’d really appreciate anyone who could guide me through this problem because this has turned super difficult at this point (for me today at least) even though it’s something simple I’m trying to do.

4 Likes

Use Instance:WaitForChild so that if the child doesn’t exist, it will yield until it does.

local proximity = game.Workspace:WaitForChild("BasementFlashlight"):WaitForChild("ProximityPrompt")
local barrier = game.Workspace:WaitForChild("BasementBarrier")

proximity.Triggered:Connect(function(var)
	barrier:Destroy()
end)
23 Likes