Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local userInputService = game:GetService("UserInputService")
- -- Ensure GUI persists after death
- local screenGui = Instance.new("ScreenGui")
- screenGui.ResetOnSpawn = false -- GUI will not reset on death
- screenGui.Parent = player:WaitForChild("PlayerGui")
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.3, 0, 0.15, 0)
- button.Position = UDim2.new(0.35, 0, 0.75, 0)
- button.Text = "Tap to Survive!"
- button.TextScaled = true
- button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
- button.Draggable = true -- Make the button draggable
- button.Active = true -- Required for dragging
- button.Parent = screenGui
- local timerLabel = Instance.new("TextLabel")
- timerLabel.Size = UDim2.new(0.2, 0, 0.1, 0)
- timerLabel.Position = UDim2.new(0.4, 0, 0.1, 0)
- timerLabel.Text = "Time: 5"
- timerLabel.TextScaled = true
- timerLabel.BackgroundTransparency = 1
- timerLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
- timerLabel.Parent = screenGui
- local clickCount = 0
- local requiredClicks = 10
- local isGameOver = false
- local timeLeft = 5
- local waitingForJump = false
- -- Function to make the player explode
- local function explodePlayer()
- if player.Character then
- local character = player.Character
- local explosion = Instance.new("Explosion")
- explosion.Position = character:GetPrimaryPartCFrame().p
- explosion.Parent = workspace
- wait(0.2)
- character:BreakJoints() -- Respawn the player
- end
- end
- -- Timer function
- local function startTimer()
- timeLeft = 5
- while timeLeft > 0 and not isGameOver do
- timerLabel.Text = "Time: " .. timeLeft
- wait(1)
- timeLeft = timeLeft - 1
- end
- if not isGameOver then
- timerLabel.Text = "BOOM! Jump to Restart!"
- explodePlayer() -- Player explodes when time reaches 0
- waitingForJump = true -- Must jump to restart
- end
- end
- -- Start timer when the game begins
- task.spawn(startTimer)
- local function onButtonClick()
- if isGameOver then return end
- clickCount = clickCount + 1
- button.Text = "Taps: " .. clickCount .. "/" .. requiredClicks
- -- Check if player won
- if clickCount >= requiredClicks then
- isGameOver = true
- waitingForJump = true
- button.Text = "You Survived!"
- button.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Green for success
- timerLabel.Text = "Jump to Restart!"
- end
- end
- -- Detect player jump to restart game (Mobile & PC)
- userInputService.JumpRequest:Connect(function()
- if waitingForJump then
- -- Reset the game
- clickCount = 0
- isGameOver = false
- waitingForJump = false
- button.Text = "Tap to Survive!"
- button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
- timerLabel.Text = "Time: 5"
- startTimer()
- end
- end)
- button.MouseButton1Click:Connect(onButtonClick)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement