Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Module = {IsActive = false}
- local PlayerGui = game.Players.LocalPlayer.PlayerGui
- local DebrisClass = require(game.ReplicatedStorage.Debris)
- local Config = require(game.ReplicatedStorage["Code door config"])
- local SFX = game.SoundService.SFX
- local Remote = game.ReplicatedStorage["Validate code"]
- local function Tween(Item: Instance, Info: TweenInfo, PropertyTable: {[string]: any}): Tween
- local T = game.TweenService:Create(Item,Info,PropertyTable)
- T:Play()
- return T
- end
- function Module.Enable()
- Module.IsActive = true
- local Gui = PlayerGui["Code gui"]
- local Frame = Gui.Frame
- local Buttons = Frame.Buttons
- local Numpad = Buttons.Numpad
- local Display = Frame.Display
- local Invalid = Frame.Invalid
- local Debris = DebrisClass.new()
- local Code = table.create(Config.NumDigits,"*")
- local At = 0
- local ButtonTweenInfo = TweenInfo.new(.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
- local WaitingThreads = {} -- Only really stores the thread for "SignalInvalidCode" xD
- local function SignalInvalidCode()
- if Invalid.Visible then return end
- local Thread
- SFX.Error:Play()
- Invalid.Visible = true
- Thread = task.delay(Config.InvalidCodeVisibleDuration,function()
- Invalid.Visible = false
- table.remove(WaitingThreads,table.find(WaitingThreads,Thread))
- end)
- table.insert(WaitingThreads,Thread)
- end
- local function Close()
- Module.IsActive = false
- Frame.Visible = false
- Invalid.Visible = false -- In case its visible.
- Debris.Clean()
- for i = #WaitingThreads,1,-1 do local Thread = WaitingThreads[i] table.remove(WaitingThreads,i) task.cancel(Thread) end
- end
- local function UpdateDisplay(Method: string, Digit: string)
- if Method == "Add" then
- if At + 1 > Config.NumDigits then return end
- At += 1
- end
- Code[At] = Digit
- Display.Text = table.concat(Code,"")
- if Method == "Back" then -- We got this in its own if statement cuz having it togheter with the first one causes it to not update the display properly.
- if At - 1 < 0 then return end
- At -= 1
- end
- end
- local function TweenButton(Btn: TextButton)
- if Btn:HasTag("Tweening") then return end
- local OldSize = Btn.Size
- Btn:AddTag("Tweening")
- Tween(Btn,ButtonTweenInfo,{Size = UDim2.fromScale(OldSize.X.Scale-0.08,OldSize.Y.Scale-0.08)}).Completed:Once(function()
- Tween(Btn,ButtonTweenInfo,{Size = OldSize}).Completed:Wait()
- Btn:RemoveTag("Tweening")
- end)
- end
- Frame.Visible = true
- Display.Text = table.concat(Code,"")
- for _, v in Numpad:GetChildren() do
- if not tonumber(v.Name) then continue end
- local Btn = v.Button
- Debris.Add(Btn.MouseButton1Click:Connect(function()
- SFX.Click:Play()
- UpdateDisplay("Add",Btn.Text)
- TweenButton(Btn)
- end))
- end
- Debris.Add({
- Numpad["Go back"].Button.MouseButton1Click:Connect(function()
- SFX.Submit:Play()
- UpdateDisplay("Back","*")
- end),
- Numpad.Submit.Button.MouseButton1Click:Connect(function()
- SFX.Submit:Play()
- if Remote:InvokeServer(tonumber(table.concat(Code,""))) then
- Close()
- else
- SignalInvalidCode()
- end
- end),
- Buttons.Close.MouseButton1Click:Connect(function() SFX.Submit:Play() Close() end)
- })
- end
- return Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement