Disabling and enabling proximity prompts from local scripts

What I am trying to achieve

I have been struggling to create a camera lock system when interacting with a proximity prompt. Currently I have a part with a proximity prompt inside and whenever a player interacts with that proximity prompt their camera will be locked to the part parent of that proximity prompt. Once a players screen is locked to the part a GUI is cloned on their screen which allows them to exit the screen lock. However I have been trying to code it where if a player interacts with the proximity prompt, it will disable the proximity prompt so no other player can interact with it while a player already has their screen locked to the part. This makes it where only one player can use the proximity prompt at a time.

The Problem

Although it seems that disabling and enabling proximity prompts only work for every player in a server for normal scripts, not local scripts. I was wondering how I can go about fixing this.

My script

Here is the local script that I have in StarterPlayerScripts.

local camera = workspace.CurrentCamera
local part = game.Workspace.ViewPart -- Assuming the LocalScript is placed inside the part with the proximity prompt
local player = game.Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("MyRemoteEvent")
camera.CameraType = Enum.CameraType.Scriptable

local function LockCameraToPart()
	part.ProximityPrompt.Enabled = false
	player.PlayerGui.ScreenGui.TextButton.LocalScript.Disabled = true
	player.CameraMode = Enum.CameraMode.LockFirstPerson
	camera.CameraSubject = part
end

local function OnChanged()
	camera.CFrame = part.CFrame
end

local function RevertCamera()
	part.ProximityPrompt.Enabled = true
	player.PlayerGui.ScreenGui.TextButton.LocalScript.Disabled = false
	player.CameraMode = Enum.CameraMode.LockFirstPerson
	camera.CameraSubject = player.Character.Humanoid
	camera.CameraType = Enum.CameraType.Custom
end

local function OnPromptTriggered()
	LockCameraToPart()

	local exitButton = replicatedStorage:WaitForChild("ExitButton"):Clone()
	exitButton.Parent = player.PlayerGui

	exitButton.TextButton.MouseButton1Click:Connect(function()
		exitButton:Destroy()
		RevertCamera()
	end)
end

part.ProximityPrompt.Triggered:Connect(OnPromptTriggered)

To set up something like this you’ll need a local script and a server script. Essentially when the player clicks the proximity prompt, they’ll fire a Remote Event. The server connects to that remote, and disables the proximity prompt. Then, when the player wants to leave the part, they fire the remote again. This time, the server turns the proximity prompt back on.

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