Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Remote = game.ReplicatedStorage["Validate code"]
- local Config = require(game.ReplicatedStorage["Code door config"])
- local DoorModel = workspace.Door
- local DoorLight = DoorModel["Light indicator"]
- local Door = DoorModel.Door
- local DoorPrompt = DoorModel.Remote.Prompt
- local ToggleRemoteGui = game.ReplicatedStorage["Toggle code gui"]
- local function Tween(Item: Instance, Info: TweenInfo, PropertyTable: {[string]: any}): Tween
- local T = game.TweenService:Create(Item,Info,PropertyTable)
- T:Play()
- return T
- end
- local function ToggleDoor(IsDisabled: boolean)
- if IsDisabled then
- DoorPrompt.Enabled = false
- DoorModel:SetAttribute("Open",true)
- DoorLight.Color = Color3.fromRGB(0, 255, 0)
- else
- DoorPrompt.Enabled = true
- DoorModel:SetAttribute("Open",false)
- DoorLight.Color = Color3.fromRGB(196, 40, 28)
- end
- end
- local function OpenDoor()
- local Info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
- ToggleDoor(true)
- Tween(Door,Info,{CFrame = Door.CFrame + Door.CFrame.UpVector*10}).Completed:Once(function()
- task.wait(2)
- Tween(Door,Info,{CFrame = Door.CFrame + Door.CFrame.UpVector*-10}).Completed:Wait()
- ToggleDoor(false)
- end)
- end
- local function OnCodeValidate(Player: Player, Code: number)
- if typeof(Code) ~= "number" then return end
- if Code == Config.CorrectCode and not DoorModel:GetAttribute("Open") then
- OpenDoor()
- return true
- end
- return false
- end
- Remote.OnServerInvoke = OnCodeValidate
- DoorPrompt.Triggered:Connect(function(Player: Player)
- ToggleRemoteGui:FireClient(Player)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement