Using Remote Event To Destroy Proximity Prompt on client side

Hi there!
I am trying to destroy a proximity prompt once it is triggered by the player. Client side destroy.

This script is Server Sided

game.Workspace["ID Printer"]:WaitForChild("ID Printer Prompt").Triggered:Connect(function(player)
	task.wait()
	print(player)
	IDPP:FireClient(player)
end)

This local script is stored in the workspace, parent to the part.
The remote event is also stored in ReplicatedStorage

Running the script would show no error and according to my understanding the player consists of the player’s name that triggered the prompt.

local IDPP = game:GetService("ReplicatedStorage"):WaitForChild("ID Printer")

IDPP.OnClientEvent:Connect(function(player)
        print("hi")
	local printer = game.Workspace["ID Printer"]
	printer:FindFirstChild("ID Printer Prompt"):Destroy()
end)

I tried running print() command in the local script to check if it even connects, but it did not work. Am I missing something?

I manage to make the script work by placing the local script into StarterPlayer.StarterPlayerScripts but I am unsure if there are any flaws in doing so.

2 Likes

hit is used for Touched Events. I am not very educated when it comes to proximity prompts so correct me if I am wrong.

2 Likes

Yeah you are not wrong. My hit here just means the Player.

Update: Just changed the hit to player to avoid confusion.

Can’t you just used
Example:

Script.Parent:WaitForChild(“ProximityPrompt”):Destroy()

If you are talking about the Local Script, it would not connect. Else if you are referring to the Server Script it will be destroyed for other players too, which is not my goal to do so.

You just wanted to destroy the promt to the only player that triggered it

Where did you put the LocalScript that connects to the remoteEvent?

The parent of localscript has to be in the service StarterCharacterScripts or StarterPlayerScripts.
I recommend you to pass the object as an argument which after modifying the script, it should look like this

game.Workspace["ID Printer"]:WaitForChild("ID Printer Prompt").Triggered:Connect(function(player)
	task.wait()
	print(player)
	IDPP:FireClient(player,script.Parent)
end)

In this way, there won’t be any error in finding ID Printer in the above line that you’ve written in localscript

local printer = game.Workspace["ID Printer"]

After making the necessary changes by passing the argument, your localscript ( Parented to the service StarterCharacterScripts or StarterPlayerScripts) should look like this

local IDPP = game:GetService("ReplicatedStorage"):WaitForChild("ID Printer")
IDPP.OnClientEvent:Connect(function(script.Parent)
        print("hi")
	script.Parent:Destroy()
end)

The parents of localscript should always be the service StarterCharacterScripts or StarterPlayerScripts in order for it to work

Incorrect. I am 99% sure that player is not passed as a variable since the client can get it’s own player. (The last code block)

The issue was being caused because LocalScripts don’t work when parented to Parts inside of workspace

LocalScripts only work when they’re inside of (descendants of):

  • StarterPlayerScripts
  • StarterCharacterScripts
  • Guis inside StarterGui or PlayerGui
  • ReplicatedFirst
  • Tools

Here’s the doc link where it explains this:

1 Like

That’s the parameter the server has to pass, but the OnClientEvent wont receive the player parameter. Try It Out.
Server:

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.PlayerGui:WaitForChild("RemoteEvent",math.huge):FireClient(plr,"lol")
end)

Client:

script.Parent.OnClientEvent:Connect(function(data)
	print(data)
end)

(Inside of starterGui, RemoteEvent I created)

2 Likes

My bad… I must’ve overlooked such an error

1 Like

Placed the local script in StarterPlayer.StarterPlayerScripts and it worked. But are there any flaws in doing so?

The player variable prints out the player’s username.

LocalScripts are meant to be used inside StarterPlayerScripts, so there’s no need to worry about doing so

1 Like

Alrighty thanks. You are right about the client sided not passing the player into the local script. I just tested and it printed “nil”, but it worked on the server side script.

Oh that wasn’t me that said that, it was @unidentifiedObject51

They are correct though

1 Like

My bad. this for you @unidentifiedObject51 :grinning:

I don’t know if I deserve the solution or @unidentifiedObject51 since if what they said was causing you problems, they deserve it more than me since I didn’t mention it

1 Like

True. Your solution privileges has been revoked, title will be inherited by @unidentifiedObject51 .

2 Likes