Hello! I am new to scripting and I’ve recently made this with some help from the Roblox Documentation. For some reason, it doesn’t work and I can’t find the error.
The thing I want to achieve is that when you use the proximityprompt the door opens and when you use it again it closes
The issue is that when I use it doesn’t work.
Here’s a video:
I’ve tried asking other people for help but it didn’t work.
Here’s the script:
local ProximityPromptService = game:GetService("ProximityPromptService")
local door = game.Workspace.DoorLobby
closed = true
local function open()
door.CanCollide = false
door.Transparency = 0.5
end
local function close()
door.CanCollide = true
door.Transparency = 0
end
ProximityPromptService.PromptButtonHoldEnded:Connect(function()
if closed == true then
open()
closed = false
end
if closed == false then
close()
closed = true
end
end)
I would really appreciate if you helped me. Thank you for reading.
Hi, is there 2 DoorLobby in your workspace? This should be the problem there. I also see that you are using the event PromptButtonHoldEnded and you are also using the service: ProximityPromptService for making script like this you need to make something like this:
local door = game.Workspace.DoorLobby
local prox = path.to.proximityPrompt
closed = true
local function open()
door.CanCollide = false
door.Transparency = 0.5
end
local function close()
door.CanCollide = true
door.Transparency = 0
end
prox.Triggered:Connect(function()
closed = not closed
if closed == true then
close()
else
open()
end
end)
You just need to change the variable prox to your proximity prompt instance!