How to make a proximity prompt disabled for other players when in use?

I’m currently working on making a robbing system utilizing the ProximityPromptService - however I’m having difficulty figuring out a way to make it so that the prompt will be disabled for other players when it’s being held down / is in use.

I couldn’t find any useful tutorials related to this - if anybody could help, it would save me from having an aneurysm.

CODE:

  local prompt = script.Parent
  local lastRob = 0
  local regen = 120
  prompt.PromptButtonHoldBegan:Connect(function(plr)
	game.ReplicatedStorage.Alarm:FireAllClients("JEWELRY STORE IS BEING ROBBED",plr.Name)
	prompt.ActionText = "BEING ROBBED"
	prompt.Script.Robber.Value = plr.Name
end)


prompt.PromptButtonHoldEnded:Connect(function(plr)
	prompt.ActionText = "ROB STORE"
	prompt.Script.Robber.Value = "none"
end)

prompt.Triggered:Connect(function(plr)
	if tick()-lastRob >= regen then
		lastRob = tick()
		script.Parent.Parent.Transparency = 1
		local robcash = math.rad(2500,10000)
		game.ServerStorage.Data[plr.Name.."Cash"].Value = game.ServerStorage.Data[plr.Name.."Cash"].Value + robcash
		game.ReplicatedStorage.Alarm:FireAllClients("JEWELRY STORE HAS BEEN ROBBED",plr.Name)
		prompt.ActionText = "ROB STORE"
		wait(regen)
		script.Parent.Parent.Transparency = 0
prompt.Script.Robber.Value = "none"
	end
end)

if prompt.Script.Robber.Value == "none" then
	prompt.Enabled = true
end

I don’t know how to work with ProximityPromptService, but what I would do is create a table, where I would store whether each prompt is in use. Key being the prompt, or anything that is unique to each prompt, and can be used to identify it; value being true or false depending on whether the prompt is in use. Whenever the prompt is tried to be accesed, I would check the value in that table with the prompt being the key (or anything else to identify the prompt), and if the value is false, I will make it true, and then do all the other stuff. When the prompt is no longer in use, I would change the value under the key used before, to false.

Edit: Of course, if you later find out that there is a built-in property that each prompt has, that indicates whether the prompt is in use, then you should use that instead.

First, insert a RemoteEvent into ReplicatedStorage named “HidePrompt”, and put this into your script.

prompt.PromptButtonHoldBegan:Connect(function(holder) 
	for _,plr in pairs(game.Players:GetPlayers()) do
		if plr.Name ~= holder.Name then
			game.ReplicatedStorage.HidePrompt:FireAllClients(prompt,false)
		end
	end
end)

prompt.PromptButtonHoldEnded:Connect(function(holder)
	for _,plr in pairs(game.Players:GetPlayers()) do
		if plr.Name ~= holder.Name then
			game.ReplicatedStorage.HidePrompt:FireAllClients(prompt,true)
		end
	end
end)

Next, insert a LocalScript into either StarterPack, StarterGui, or StarterPlayerScripts (which is in StarterPlayer).

game.ReplicatedStorage.HidePrompt.OnClientEvent:Connect(function(prompt,value)
	prompt.Enabled = value
end)

I’ve tested this myself, and it even works with custom prompts.

1 Like

Wouldn’t that only enable it for that specific client? Client scripts (a.k.a local scripts) never replicate to the server and other clients. So, even if prompt.Enabled will be set to true by the local script, all the other local scripts and the server script will think that prompt.Enabled is still false.

So, instead it is better to make a table in a server script and store the values there, (explanation is in my post above)