Prox Prompt Scripting Eror

I’m trying to make an escape room, and I want to add more than 2 doors eventually but I need these 2 doors to work first. So basically the first door you click and put in the code for works perfectly. But if you do door 1 before door 2 then door2’s prompt does not bring up the Screen gui. But if you do door2 then door1, door 1 works fine? I asked AI for help but it… its ai and it’s not perfect yet lol.
LOCAL SCRIPT IN STARTER GUI>SCREEN GUI (Named keypad1)

local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local Folder = game.Workspace.Doors
local Frame = script.Parent.Frame
local code = ""
local currentDoor = nil -- Store the currently triggered door

local function buttonClicked(button)
	return function()
		script.Parent.Frame.Screen.Text = script.Parent.Frame.Screen.Text .. button.Name
	end
end

local buttons = {} -- Define buttons
for i = 0, 9 do
	buttons[tostring(i)] = script.Parent.Frame.Buttons[tostring(i)]
end
local buttonEnter = script.Parent.Frame.Buttons["Enter"]
local buttonClear = script.Parent.Frame.Buttons["Clear"]

for i = 0, 9 do
	buttons[tostring(i)].MouseButton1Click:Connect(buttonClicked(buttons[tostring(i)]))
end

local function promptTriggered(door)
	print("Clicked Prompt for Door: " .. door.Name)
	Frame.Visible = true
	code = door.Keypad.Code.Value
	currentDoor = door -- Store the reference to the triggered door
end

for index, door in pairs(Folder:GetChildren()) do
	local prompt = door:WaitForChild("Keypad"):WaitForChild("Frame"):WaitForChild("ProximityPrompt")
	prompt.Triggered:Connect(function()
		promptTriggered(door) -- Pass the specific door to the promptTriggered function
	end)
end

local cancelButton = script.Parent.Frame.Cancel
cancelButton.MouseButton1Click:Connect(function()
	script.Parent.Frame.Visible = false
	script.Parent.Frame.Screen.Text = ""
end)

buttonEnter.MouseButton1Click:Connect(function()
	if currentDoor and script.Parent.Frame.Screen.Text == code then
		print("Correct")
		script.Parent.Frame.Screen.Text = ""
		script.Parent.Frame.Visible = false
		game.ReplicatedStorage[currentDoor.Name]:FireServer()
	else
		script.Parent.Frame.Screen.Text = "Incorrect!"
		wait(1)
		script.Parent.Frame.Screen.Text = ""
	end
end)

buttonClear.MouseButton1Click:Connect(function()
	script.Parent.Frame.Screen.Text = ""
end)

Door1 First
robloxapp-20240402-1036177.wmv (778.5 KB)

Door2first
robloxapp-20240402-1036440.wmv (1012.8 KB)

LOCAL SCRIPT IN SPS

local RE = game.ReplicatedStorage.Door1
RE.OnClientEvent:Connect(function()
	if  game.Players.LocalPlayer.PlayerGui.Keypad1 then
		game.Players.LocalPlayer.PlayerGui.Keypad1:Destroy()
	end
	if  	game.Workspace.Doors.Door1.Keypad.Frame.ProximityPrompt then
		game.Workspace.Doors.Door1.Keypad.Frame.ProximityPrompt:Destroy()
	end

end)

local RE2 = game.ReplicatedStorage.Door2
RE2.OnClientEvent:Connect(function()
	if  game.Players.LocalPlayer.PlayerGui.Keypad1 then
		game.Players.LocalPlayer.PlayerGui.Keypad1:Destroy()
	end
	if  	game.Workspace.Doors.Door2.Keypad.Frame.ProximityPrompt then
		game.Workspace.Doors.Door2.Keypad.Frame.ProximityPrompt:Destroy()
	end

end)
1 Like

I fixed it somehow, thanks for viewing

1 Like