SCP game Doors Script Support

Hello! this is my first DevForum post,

So I’m a game developer and I’m currently making an SCP game which is going pretty well, but my biggest issue is that I do not have any scripting experience.

The current issue I’m having is making gates and doors, which I already have and work but the problem is a manual opening and closing, so the door/gate can remain open till someone decides to close it.

I’ve tried to read the script, look up some tutorials, try to modify stuff but still couldn’t get it done, is anyone able to help me?

Heres the gate code (which I will apply to the doors once (if) fixed)

local TweenService = game:GetService(“TweenService”)
local gate = script.Parent
local is_gate_busy = true

– Main settings for the door opening sequence
local tween_info = TweenInfo.new(
8, – Opening time
Enum.EasingStyle.Sine, – The way it opens (Check official Roblox docs for more info)
Enum.EasingDirection.Out, – EasingStyle direction
0, – 0 = doesn’t repeat
false – false = doesn’t reverse
)

– These are for changing the position of the gate
local originalPosition = gate.Position
local newPosition = gate.Position + Vector3.new(0, 8, 0)
local tween = TweenService:Create(gate, tween_info, {Position = newPosition})
local tween2 = TweenService:Create(gate, tween_info, {Position = originalPosition})

– These are the door clearances, duh (true = opens, false = doesn’t open)
local keycard_clearance = {
[“L1 Clearance”] = false,
[“L2 Clearance”] = false,
[“L3 Clearance”] = true,
[“L4 Clearance”] = true,
[“L5 Clearance”] = true
}

– The main function that makes the gate open
function onTriggered(player)
local clearance_character = player.Character:FindFirstChildWhichIsA(“Tool”)
local clearance_backpack = player.Backpack:FindFirstChildWhichIsA(“Tool”)
if keycard_clearance[(clearance_character or clearance_backpack).Name] and is_gate_busy then
print(“Access granted.”)
is_gate_busy = false
gate.DoorSound:play()
gate.DoorAlarm:play()
gate.AccessGranted:play()
wait(0.5)
tween:Play()
wait(10)
tween2:Play()
wait(8)
gate.DoorSound:Stop()
wait(2)
gate.DoorAlarm:Stop()
is_gate_busy = true
elseif not keycard_clearance[(clearance_character or clearance_backpack).Name] and is_gate_busy then
print(“Access denied.”)
is_gate_busy = false
gate.AccessDenied:play()
wait(1)
is_gate_busy = true
end
end

– These connect the readers to the function onTriggered
gate.Parent.reader1.ProximityPrompt.Triggered:Connect(onTriggered)
gate.Parent.reader2.ProximityPrompt.Triggered:Connect(onTriggered)


3 Likes

Okay, so in your case the door closes itself after some seconds, I will make a script for you!

1 Like

Here is the code:
local TweenService = game:GetService(“TweenService”)
local gate = script.Parent
local is_gate_busy = true
local opened = false

– Main settings for the door opening sequence
local tween_info = TweenInfo.new(
8, – Opening time
Enum.EasingStyle.Sine, – The way it opens (Check official Roblox docs for more info)
Enum.EasingDirection.Out, – EasingStyle direction
0, – 0 = doesn’t repeat
false – false = doesn’t reverse
)

– These are for changing the position of the gate
local originalPosition = gate.Position
local newPosition = gate.Position + Vector3.new(0, 8, 0)
local tween = TweenService:Create(gate, tween_info, {Position = newPosition})
local tween2 = TweenService:Create(gate, tween_info, {Position = originalPosition})

– These are the door clearances, duh (true = opens, false = doesn’t open)
local keycard_clearance = {
[“L1 Clearance”] = false,
[“L2 Clearance”] = false,
[“L3 Clearance”] = true,
[“L4 Clearance”] = true,
[“L5 Clearance”] = true
}

– The main function that makes the gate open
function onTriggered(player)
local clearance_character = player.Character:FindFirstChildWhichIsA(“Tool”)
local clearance_backpack = player.Backpack:FindFirstChildWhichIsA(“Tool”)
if keycard_clearance[(clearance_character or clearance_backpack).Name] and is_gate_busy then
print(“Access granted.”)
is_gate_busy = false
gate.DoorSound:play()
gate.DoorAlarm:play()
gate.AccessGranted:play()
wait(0.5)
if not opened then
tween:Play()
opened = true
else
tween2:Play()
opened = false
end
wait(8)
gate.DoorSound:Stop()
wait(2)
gate.DoorAlarm:Stop()
is_gate_busy = true
elseif not keycard_clearance[(clearance_character or clearance_backpack).Name] and is_gate_busy then
print(“Access denied.”)
is_gate_busy = false
gate.AccessDenied:play()
wait(1)
is_gate_busy = true
end
end

– These connect the readers to the function onTriggered
gate.Parent.reader1.ProximityPrompt.Triggered:Connect(onTriggered)
gate.Parent.reader2.ProximityPrompt.Triggered:Connect(onTriggered)

Also, you should fix your code/script, it should look like this:

2 Likes

Make sure the script is server-sided to make it works for everyone.

1 Like

Please avoid having people rewrite your script, and make sure you use “```” at the start and end of your script to create a code block.

1 Like

Thank you very much and I apologize for having you to rewrite the whole script!

2 Likes

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