Proximity prompt not enabling/disabling

Hi,
I’ve recently been having some problems with enabling and disabling proximity prompts through remote functions. Right now I have three parts which all contain proximity prompts. I have a local script in StarterPlayerScripts that fires a remote event through one of the three proximity prompt interactions. The remote event connects to a script which should then disable/enable the proximity prompt but does not. Basically I am trying to make it where when a player interacts with a proximity prompt, it will then fire a remote and disable/enable the proximity prompt while also playing a sound.

Here is not the local script but the script that I have so far.

local replicatedStorage = game:GetService("ReplicatedStorage")
local EnableInteractionEvent = replicatedStorage:WaitForChild("EnableInteraction")
local DisableInteractionEvent = replicatedStorage:WaitForChild("DisableInteraction")

local part = game.Workspace.LockerInteract
local part2 = game.Workspace.GarbageBagInteract
local part3 = game.Workspace.VentInteract

local sound = part:WaitForChild("Sound")
local sound2 = part2:WaitForChild("Sound")
local sound3 = part3:WaitForChild("Sound")

local function HandleInteraction(part, sound, prompt, enabled)
		sound:Play()
	end

local function EnableInteraction(part, sound, prompt)
	HandleInteraction(part, sound, prompt, true)
end

local function DisableInteraction(part, sound, prompt)
	HandleInteraction(part, sound, prompt, false)
end

local function EnableLocker()
	local prompt = part:FindFirstChild("ProximityPrompt")
	EnableInteraction(part, sound, prompt)
end

local function DisableLocker()
	local prompt = part:FindFirstChild("ProximityPrompt")
	DisableInteraction(part, sound, prompt)
end

local function EnableGarbageBag()
	local prompt = part2:FindFirstChild("ProximityPrompt")
	EnableInteraction(part2, sound2, prompt)
end

local function DisableGarbageBag()
	local prompt = part2:FindFirstChild("ProximityPrompt")
	DisableInteraction(part2, sound2, prompt)
end

local function EnableVent()
	local prompt = part3:FindFirstChild("ProximityPrompt")
	EnableInteraction(part3, sound3, prompt)
end

local function DisableVent()
	local prompt = part3:FindFirstChild("ProximityPrompt")
	DisableInteraction(part3, sound3, prompt)
end

local function HandleInteractionRequest(player, partName, enable)
	if partName == "Locker" then
		if enable then
			EnableLocker()
		else
			DisableLocker()
		end
	elseif partName == "GarbageBag" then
		if enable then
			EnableGarbageBag()
		else
			DisableGarbageBag()
		end
	elseif partName == "Vent" then
		if enable then
			EnableVent()
		else
			DisableVent()
		end
	end
end

EnableInteractionEvent.OnServerEvent:Connect(function(player, partName)
	HandleInteractionRequest(player, partName, true)
end)

DisableInteractionEvent.OnServerEvent:Connect(function(player, partName)
	HandleInteractionRequest(player, partName, false)
end)

Please tell me how I can achieve this, thanks.

3 Likes

I am unsure if this is what you expect, but this idea is based on the text at the beginning of your message. Do you really need the server in the scenario? You can perform all of this on the client, only disabling the proximity prompt and playing the sound to the current client, not the server. Please tell me if you were expecting something else. Here is the client code, which can go in StartPlayerScripts as you stated originally.

local locker = workspace.Locker
local garbage = workspace.GarbageBag
local vent = workspace.Vent

local ls = locker:WaitForChild("Sound")
local gs = garbage:WaitForChild("Sound")
local vs = vent:WaitForChild("Sound")

locker.ProximityPrompt.Triggered:Connect(function (plr)
	if plr == game.Players.LocalPlayer then
		ls:Play()
		locker.ProximityPrompt.Enabled = false
	end
end)

garbage.ProximityPrompt.Triggered:Connect(function (plr)
	if plr == game.Players.LocalPlayer then
		gs:Play()
		garbage.ProximityPrompt.Enabled = false
	end
end)

vent.ProximityPrompt.Triggered:Connect(function (plr)
	if plr == game.Players.LocalPlayer then
		vs:Play()
		vs.ProximityPrompt.Enabled = false
	end
end)

If something is not right or does not work for you, please let me know as this is one of my first posts.

1 Like

Hi, thanks for the response. I’ll try this out when I get home later. But I would prefer as for it to be server sided as I want the sounds and proximity prompts to be disabled and enabled for every player in the server, not just the local player.

1 Like

Alright, you can modify the script I provided to not check the player on an interaction, pretty much removing the if statements. You can perform client-sided actions by using the script I provided earlier, but only performing actions needed on the client side!

2 Likes

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