Advertisement
Herobrinekid2

Code server

Jan 4th, 2025
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | Source Code | 0 0
  1. local Remote = game.ReplicatedStorage["Validate code"]
  2. local Config = require(game.ReplicatedStorage["Code door config"])
  3.  
  4. local DoorModel = workspace.Door
  5. local DoorLight = DoorModel["Light indicator"]
  6. local Door = DoorModel.Door
  7. local DoorPrompt = DoorModel.Remote.Prompt
  8. local ToggleRemoteGui = game.ReplicatedStorage["Toggle code gui"]
  9.  
  10.  
  11.  
  12. local function Tween(Item: Instance, Info: TweenInfo, PropertyTable: {[string]: any}): Tween
  13.     local T = game.TweenService:Create(Item,Info,PropertyTable)
  14.  
  15.     T:Play()
  16.     return T
  17. end
  18.  
  19. local function ToggleDoor(IsDisabled: boolean)
  20.     if IsDisabled then
  21.         DoorPrompt.Enabled = false
  22.         DoorModel:SetAttribute("Open",true)
  23.         DoorLight.Color = Color3.fromRGB(0, 255, 0)
  24.     else
  25.         DoorPrompt.Enabled = true
  26.         DoorModel:SetAttribute("Open",false)
  27.         DoorLight.Color = Color3.fromRGB(196, 40, 28)
  28.     end
  29. end
  30.  
  31. local function OpenDoor()
  32.     local Info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
  33.    
  34.     ToggleDoor(true)
  35.     Tween(Door,Info,{CFrame = Door.CFrame + Door.CFrame.UpVector*10}).Completed:Once(function()
  36.         task.wait(2)
  37.         Tween(Door,Info,{CFrame = Door.CFrame + Door.CFrame.UpVector*-10}).Completed:Wait()
  38.         ToggleDoor(false)
  39.     end)
  40. end
  41.  
  42. local function OnCodeValidate(Player: Player, Code: number)
  43.     if typeof(Code) ~= "number" then return end
  44.    
  45.     if Code == Config.CorrectCode and not DoorModel:GetAttribute("Open") then
  46.         OpenDoor()
  47.         return true
  48.     end
  49.     return false
  50. end
  51.  
  52.  
  53. Remote.OnServerInvoke = OnCodeValidate
  54. DoorPrompt.Triggered:Connect(function(Player: Player)
  55.     ToggleRemoteGui:FireClient(Player)
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement