Part not destroying locally after triggering flashlight proximity

Hello,

So I’m trying to make it so when you trigger the proximity prompt coming from the flashlight, this part which will serve as a barrier will break locally. I’m not that that that experienced with scripting and so I looked up how I could break parts locally and I used a LocalScript and from what I seen, it said that it can be used the same as a normal script? Didn’t really work out for me and so I need a little help.

Clip of what’s going on:

As you see, that part that I kept walking up to after triggering the proximity is the one that should’ve been destroyed locally. Not sure if I have to somehow use RemoteEvents for this or what, I don’t really specialize in scripting.

Here’s an error that I keep seeing relating to this:

How things are set up:

Flashlight in Workspace
image
image

Barrier part in Workspace
image
image

LocalScript in StarterCharacterScripts
image

The code inside the LocalScript

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

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

The LocalScript seems to not be doing anything right now too, not so sure what I’m doing wrong from here. Could it be the way I have things set up right now? Any who, I’d appreciate any help!

3 Likes

The error is that the script isn’t detecting the parts
Maybe try adding a wait in the beginning of the local script or use a WaitForChild()

I do not believe that ProximityPrompt events fire locally and you may need to just use a server script to fire a client event to tell the client to destroy the barrier.

Also, this is being done as a Starter character script which means its in workspace which is where local scripts don’t run at all. (Correct me if I am wrong.)

How exactly would things look with this? I’ve been trying for the past 10 minutes and am a bit confused on how I’d go about it. Already made a RemoteEvent named “DestroyBarrierEvent” and put a server script inside the flashlight to try and fire it so the LocalScript can try to destroy the part on the client. I also looked at some other threads right now that could help but not much luck, a bit confusing for me as I don’t have much experience with scripting in calling RemoteEvents and such.

Here’s what the server script inside the flashlight looks like:

local proximity = script.Parent.ProximityPrompt
local barrier = game.Workspace.BasementBarrier
local plr = game.Players:GetPlayerFromCharacter("")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("DestroyBarrierEvent")

proximity.Triggered:Connect(function(var)
	Remote:FireEvent(plr)
end)

The LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remote = ReplicatedStorage:WaitForChild("DestroyBarrierEvent")

local Barrier = game.Workspace.BasementBarrier

Remote.OnClientEvent:Connect(function()

Barrier:Destroy()

end)

Also got a RemoteEvent called DestroyBarrierEvent.

Even though all of this I’m still getting the error of

And this new one
image

Not sure how it happened but what value should the object be set to?

I’d appreciate a bit more explanation for it.

Hello, basically what your (normal) script (line 3) is searching “” this (aka nothing)

I figured that out but what I’d like to know how is how could these 2 errors be fixed? I’ve tried so many times with different ways from what I could find but nothing works yet.