Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local players = game:GetService("Players")
- local runService = game:GetService("RunService")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local userInputService = game:GetService("UserInputService")
- local remoteEvents = replicatedStorage:WaitForChild("RemoteEvents")
- local winpadTouchedEvent = remoteEvents:WaitForChild("WinpadTouched")
- local remoteFunctions = replicatedStorage:WaitForChild("RemoteFunctions")
- local getTimerFunction = remoteFunctions:WaitForChild("GetTimer")
- local player = players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- local localGui = playerGui:WaitForChild("LocalGUI")
- local timerFrame = localGui:WaitForChild("Timer")
- local timerMain = timerFrame:WaitForChild("TimerMain")
- local currentTowerLabel = timerFrame:WaitForChild("CurrentTower")
- local restartLabel = localGui:WaitForChild("RestartLabel")
- local portals = workspace:WaitForChild("Portals")
- local towers = workspace:WaitForChild("Towers")
- local timerRunning = false
- local currentTower = ""
- local restartKey = Enum.KeyCode.R
- local restartKeyHolding = false
- local restartTime = 1
- local restartHold = 0
- local timer = 0
- function SetupPortals()
- for i, portal in pairs(portals:GetChildren()) do
- if portal:FindFirstChild("Tower") then
- portal.Touched:Connect(function(hit)
- if currentTower ~= "" then return end
- if hit and hit.Parent:FindFirstChild("Humanoid") then
- if hit.Parent == player.Character then
- currentTower = portal.Tower.Value
- hit.Parent.HumanoidRootPart.CFrame = towers:FindFirstChild(portal.Tower.Value).SpawnLocation.CFrame + Vector3.new(0, 1, 0)
- timerRunning = true
- currentTowerLabel.TextColor3 = portal.Color
- end
- end
- end)
- end
- end
- portals.ChildAdded:Connect(function(portal)
- if portal:FindFirstChild("Tower") then
- portal.Touched:Connect(function(hit)
- if currentTower ~= "" then return end
- if hit and hit.Parent:FindFirstChild("Humanoid") then
- if hit.Parent == player.Character then
- currentTower = portal.Tower.Value
- hit.Parent.HumanoidRootPart.CFrame = towers:FindFirstChild(portal.Tower.Value).SpawnLocation.CFrame + Vector3.new(0, 1, 0)
- timerRunning = true
- currentTowerLabel.TextColor3 = portal.Color
- end
- end
- end)
- end
- end)
- end
- function TimerText()
- local milsecs = tostring((timer - math.floor(timer)) * 1000)
- local seconds = tostring(math.floor(timer % 60))
- local minutes = tostring(math.floor(timer / 60))
- if #milsecs == 1 then milsecs = "0"..milsecs end
- if #seconds == 1 then seconds = "0"..seconds end
- if #minutes == 1 then minutes = "0"..minutes end
- local finalString =
- minutes..":"..seconds.."."..string.sub(milsecs, 1, 2)
- return finalString
- end
- function Restart()
- restartKeyHolding = false
- timerRunning = false
- player.Character:PivotTo(towers:FindFirstChild(currentTower).SpawnLocation.CFrame * CFrame.new(0, 2.5, 0))
- wait()
- timerRunning = true
- timer = 0
- end
- runService.RenderStepped:Connect(function(delta)
- if timerRunning then
- timer += delta
- else
- timer = 0
- end
- if timerRunning then
- if restartKeyHolding then
- restartHold += delta
- if restartHold > restartTime then
- coroutine.wrap(Restart)()
- end
- else
- restartHold = 0
- end
- else
- restartKeyHolding = false
- restartHold = 0
- end
- timerMain.Text = TimerText()
- currentTowerLabel.Text = currentTower
- restartLabel.TextTransparency = 1 - (restartHold / restartTime)
- end)
- getTimerFunction.OnClientInvoke = function()
- return TimerText()
- end
- player.CharacterAdded:Connect(function()
- timerRunning = false
- currentTower = ""
- SetupPortals()
- end)
- winpadTouchedEvent.OnClientEvent:Connect(function()
- wait()
- timerRunning = false
- currentTower = ""
- end)
- userInputService.InputBegan:Connect(function(input)
- if input.KeyCode ~= restartKey then return end
- restartKeyHolding = true
- end)
- userInputService.InputEnded:Connect(function(input)
- if input.KeyCode ~= restartKey then return end
- restartKeyHolding = false
- end)
- SetupPortals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement