Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SERVICES
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local player = Players.LocalPlayer
- -- CHARACTER
- local function getHumanoid()
- local character = player.Character or player.CharacterAdded:Wait()
- return character:WaitForChild("Humanoid")
- end
- -- GUI
- local gui = Instance.new("ScreenGui")
- gui.Name = "SpeedGui"
- gui.ResetOnSpawn = false
- gui.Parent = player:WaitForChild("PlayerGui")
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 220, 0, 120)
- frame.Position = UDim2.new(0, 10, 0.4, 0)
- frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
- frame.Parent = gui
- frame.BorderSizePixel = 0
- frame.BackgroundTransparency = 0.1
- -- TITLE
- local title = Instance.new("TextLabel")
- title.Size = UDim2.new(1, 0, 0, 30)
- title.BackgroundTransparency = 1
- title.Text = "Speed Slider"
- title.TextColor3 = Color3.new(1,1,1)
- title.Font = Enum.Font.SourceSansBold
- title.TextSize = 20
- title.Parent = frame
- -- SLIDER BAR
- local sliderBar = Instance.new("Frame")
- sliderBar.Size = UDim2.new(0, 180, 0, 6)
- sliderBar.Position = UDim2.new(0, 20, 0, 45)
- sliderBar.BackgroundColor3 = Color3.fromRGB(80,80,80)
- sliderBar.Parent = frame
- sliderBar.BorderSizePixel = 0
- -- SLIDER BUTTON
- local slider = Instance.new("Frame")
- slider.Size = UDim2.new(0, 10, 0, 16)
- slider.Position = UDim2.new(0, 0, -0.8, 0)
- slider.BackgroundColor3 = Color3.fromRGB(255,255,255)
- slider.Parent = sliderBar
- slider.BorderSizePixel = 0
- -- SPEED BOX
- local speedBox = Instance.new("TextBox")
- speedBox.Size = UDim2.new(0, 180, 0, 30)
- speedBox.Position = UDim2.new(0, 20, 0, 75)
- speedBox.Text = "50"
- speedBox.ClearTextOnFocus = false
- speedBox.TextColor3 = Color3.new(1,1,1)
- speedBox.BackgroundColor3 = Color3.fromRGB(50,50,50)
- speedBox.Font = Enum.Font.SourceSans
- speedBox.TextSize = 18
- speedBox.Parent = frame
- speedBox.BorderSizePixel = 0
- -- VARIABLES
- local MIN_SPEED = 50
- local MAX_SPEED = 500
- local dragging = false
- -- APPLY SPEED
- local function setSpeed(value)
- local humanoid = getHumanoid()
- humanoid.WalkSpeed = value
- speedBox.Text = tostring(value)
- end
- -- SLIDER LOGIC
- slider.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- dragging = true
- end
- end)
- UserInputService.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- dragging = false
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
- local relativeX = math.clamp(
- input.Position.X - sliderBar.AbsolutePosition.X,
- 0,
- sliderBar.AbsoluteSize.X
- )
- local percent = relativeX / sliderBar.AbsoluteSize.X
- local speed = math.floor(MIN_SPEED + (MAX_SPEED - MIN_SPEED) * percent)
- slider.Position = UDim2.new(0, relativeX, -0.8, 0)
- setSpeed(speed)
- end
- end)
- -- TEXTBOX INPUT (ANY NUMBER = "INF SPEED")
- speedBox.FocusLost:Connect(function()
- local number = tonumber(speedBox.Text)
- if number then
- setSpeed(number)
- end
- end)
- -- DEFAULT SPEED
- setSpeed(50)
Advertisement
Add Comment
Please, Sign In to add comment