Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local workspace = game.Workspace
- local boxes = {}
- local spawnEnabled = true
- local gravityEnabled = true
- local collisionEnabled = true
- local loopTime = 1 -- Default loop time set to 1 second
- local running = true -- Flag to control the script's execution
- -- Create GUI
- local screenGui = Instance.new("ScreenGui")
- screenGui.Parent = player:WaitForChild("PlayerGui")
- -- Function to create buttons and return them for later reference
- local function createButton(name, position, onClick)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0, 200, 0, 50)
- button.Position = UDim2.new(0, position.X, 0, position.Y)
- button.Text = name
- button.Parent = screenGui
- button.MouseButton1Click:Connect(onClick)
- return button
- end
- -- Function to create text input
- local function createTextBox(name, position, onSubmit)
- local textBox = Instance.new("TextBox")
- textBox.Size = UDim2.new(0, 200, 0, 50)
- textBox.Position = UDim2.new(0, position.X, 0, position.Y)
- textBox.Text = name -- Text is set to a description of the input
- textBox.ClearTextOnFocus = false
- textBox.Parent = screenGui
- textBox.FocusLost:Connect(function(enterPressed)
- if enterPressed then
- onSubmit(textBox.Text)
- end
- end)
- return textBox
- end
- -- Create buttons and keep references
- local clearButton = createButton("Clear Boxes", Vector2.new(10, 10), function()
- for _, box in ipairs(boxes) do
- box:Destroy()
- end
- boxes = {}
- end)
- local toggleGravityButton = createButton("Toggle Gravity", Vector2.new(10, 70), function()
- gravityEnabled = not gravityEnabled
- for _, box in ipairs(boxes) do
- box.Anchored = not gravityEnabled
- end
- end)
- local toggleCollisionButton = createButton("Toggle Collision", Vector2.new(10, 130), function()
- collisionEnabled = not collisionEnabled
- for _, box in ipairs(boxes) do
- box.CanCollide = collisionEnabled
- end
- end)
- local toggleSpawningButton = createButton("Toggle Spawning", Vector2.new(10, 190), function()
- spawnEnabled = not spawnEnabled
- end)
- local loopTimeBox = createTextBox("", Vector2.new(10, 250), function(text)
- local number = tonumber(text)
- if number and number > 0 then
- loopTime = number
- else
- print("Invalid input. Please enter a positive number.")
- end
- end)
- local exitButton = createButton("Exit", Vector2.new(10, 310), function()
- running = false
- -- Remove all buttons and text boxes
- clearButton:Destroy()
- toggleGravityButton:Destroy()
- toggleCollisionButton:Destroy()
- toggleSpawningButton:Destroy()
- loopTimeBox:Destroy()
- exitButton:Destroy()
- -- Optionally remove the GUI
- screenGui:Destroy()
- end)
- local function spawnBox()
- if not spawnEnabled then return end
- local box = Instance.new("Part")
- box.Size = Vector3.new(5, 5, 5) -- Small box of size 5x5x5 studs
- local playerPosition = player.Character and player.Character.PrimaryPart.Position or Vector3.new(0, 10, 0)
- box.Position = playerPosition + Vector3.new(0, 10, 0) -- Spawn the box 10 studs above the player
- box.Anchored = not gravityEnabled
- box.CanCollide = collisionEnabled
- box.BrickColor = BrickColor.new("Bright red")
- box.Parent = workspace
- -- Add spawn sound
- local spawnSound = Instance.new("Sound", box)
- spawnSound.SoundId = "rbxassetid://4940109913"
- spawnSound:Play()
- -- Add explosion after 2 seconds
- delay(2, function()
- local explosionSound = Instance.new("Sound", box)
- explosionSound.SoundId = "rbxassetid://17567749644"
- explosionSound:Play()
- local explosion = Instance.new("Explosion")
- explosion.Position = box.Position
- explosion.Parent = workspace
- -- Destroy the box after creating the explosion
- box:Destroy()
- end)
- table.insert(boxes, box)
- end
- while running do
- spawnBox()
- wait(loopTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement