I’m working on a door that players can unlock with a proximity prompt, but I want it to have a specific functionality. When a player unlocks the door, I want it to disappear only for that player, rather than for everyone.
The problem is that, currently, my script makes the door unlock for all players once any one player unlocks it. I’ve been searching online for a solution, but I haven’t found an answer to my question.
Right now, my script only checks if the player has the key equipped to go through the door. I’d like to make it work with a proximity prompt but can’t figure out how to implement this.
The script is currently attached to the key because I also haven’t figured out how to link it directly to the door. If you could help me with that, it would be a huge help.
Here’s the script I’m using right now:
local door = game.Workspace.BlueDoor.Door
local player = script.Parent.Parent.Parent.Parent
local tool = script.Parent.Parent
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Keycard" then -- your tool name
script.Parent.Transparency = 1
script.Parent.CanCollide = false
wait(1)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
end
end)
You Have Put Script To Part. Make Sure Is A ServerScript.
Well yes but I would want to make it like with the proximity prompt like that you need to e to unlock the door but I also want to make it for only the player that has unlocked it not the other player.
If you want it to disappear for one player and stay gone you would need to use local scripts and remote events.
create a RemoteEvent inside of replicated storage
for the a script inside of the proximityprompt you could do:
local prompt = script.Parent
local doorModel = --What ever the door you want to be gone
local RemoteEvent = game.ReplicatedStorage.OpenDoorRemoteEvent
prompt.Triggered:Connect(function(player)
if player.Backpack:FindFirstChild("Keycard") then
RemoteEvent:FireClient(player, doorModel)
end
end)
then in a local script in starterplayerscripts you could do
local RemoteEvent = game.ReplicatedStorage.OpenDoorRemoteEvent
RemoteEvent.OnClientEvent:Connect(function(doorModel)
doorModel:Destroy()
end)
local prompt = script.Parent
local doorModel = --What ever the door you want to be gone
local RemoteEvent = game.ReplicatedStorage.OpenDoorRemoteEvent
prompt.Triggered:Connect(function(player)
if player.Backpack:FindFirstChild("Keycard") or player.Character:FindFirstChild("Keycard") then
RemoteEvent:FireClient(player, doorModel)
end
end)