0% found this document useful (0 votes)
19 views4 pages

Speed Control UI for Players

Uploaded by

aleksandrsozo88
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Speed Control UI for Players

Uploaded by

aleksandrsozo88
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

-- Variables to define the player and UI setup

local player = [Link]


local mouse = player:GetMouse()

-- Utility function for smooth tween animations


local function createTween(object, tweenInfo, goal)
local tweenService = game:GetService("TweenService")
local tween = tweenService:Create(object, tweenInfo, goal)
tween:Play()
return tween
end

-- Function to create the UI


local function createUI()
-- Create the ScreenGui
local screenGui = [Link]("ScreenGui")
[Link] = player:WaitForChild("PlayerGui")
[Link] = false -- Keep UI across respawns

-- Create the main UI frame with a grey background


local mainFrame = [Link]("Frame")
[Link] = [Link](0, 350, 0, 300) -- Reduced size for a more compact
UI
[Link] = [Link](0.5, -175, 0.8, -150)
mainFrame.BackgroundColor3 = [Link](100, 100, 100) -- Grey background
[Link] = 0
[Link] = screenGui

-- Add rounded corners to the frame


local UICorner = [Link]("UICorner")
[Link] = [Link](0, 15) -- Slightly smaller corner radius
[Link] = mainFrame

-- Fade-in effect for the entire frame


[Link] = 1
createTween(mainFrame, [Link](1, [Link],
[Link]), {BackgroundTransparency = 0})

-- Add a title label with a glowing effect


local titleLabel = [Link]("TextLabel")
[Link] = [Link](1, 0, 0, 35)
[Link] = [Link](0, 0, 0, 10)
[Link] = "Speed Control"
titleLabel.TextColor3 = [Link](255, 255, 255)
[Link] = 24
[Link] = 0.6
[Link] = [Link]
[Link] = 1
[Link] = [Link]
[Link] = mainFrame

-- Create the Speed Label


local speedLabel = [Link]("TextLabel")
[Link] = [Link](1, 0, 0, 25)
[Link] = [Link](0, 0, 0, 50)
[Link] = "Current Speed: 16"
speedLabel.TextColor3 = [Link](255, 255, 255)
[Link] = 20
[Link] = 0.8
[Link] = [Link]
[Link] = 1
[Link] = [Link]
[Link] = mainFrame

-- Create an input box for the player to type the desired speed
local speedInput = [Link]("TextBox")
[Link] = [Link](0, 200, 0, 40)
[Link] = [Link](0.5, -100, 0, 100)
[Link] = "Enter Speed (10-3000)"
speedInput.TextColor3 = [Link](255, 255, 255)
speedInput.BackgroundColor3 = [Link](50, 50, 170)
[Link] = 18
[Link] = [Link]
[Link] = mainFrame

-- Add rounded corners to the TextBox


local textBoxCorner = [Link]("UICorner")
[Link] = [Link](0, 12)
[Link] = speedInput

-- Function to update the player's speed


local function updateSpeed(newSpeed)
local humanoid = [Link] and
[Link]:FindFirstChild("Humanoid")
if humanoid then
newSpeed = [Link](newSpeed, 10, 3000)
[Link] = newSpeed
createTween(speedLabel, [Link](0.5), {TextTransparency = 1})
wait(0.5)
[Link] = "Current Speed: " .. [Link](newSpeed)
createTween(speedLabel, [Link](0.5), {TextTransparency = 0})
end
end

-- When the player presses Enter on the speed input box


[Link]:Connect(function(enterPressed)
if enterPressed then
local inputText = tonumber([Link])
if inputText and inputText >= 10 and inputText <= 3000 then
updateSpeed(inputText)
else
[Link] = ""
[Link] = "Invalid Speed! (10-3000)"
end
end
end)

-- Function to create buttons with advanced interactivity


local function createButton(position, text, bgColor, textColor, callback)
local button = [Link]("TextButton")
[Link] = [Link](0, 120, 0, 40)
[Link] = position
[Link] = text
button.TextColor3 = textColor
button.BackgroundColor3 = bgColor
[Link] = 16
[Link] = 0.6
[Link] = [Link]
[Link] = mainFrame

-- Add rounded corners to the button


local buttonUICorner = [Link]("UICorner")
[Link] = [Link](0, 12)
[Link] = button

-- Hover effects with animation


[Link]:Connect(function()
createTween(button, [Link](0.2, [Link],
[Link]), {Size = [Link](0, 140, 0, 45), BackgroundColor3 =
button.BackgroundColor3:Lerp([Link](255, 255, 255), 0.5)})
end)

[Link]:Connect(function()
createTween(button, [Link](0.2, [Link],
[Link]), {Size = [Link](0, 120, 0, 40), BackgroundColor3 =
bgColor})
end)

button.MouseButton1Click:Connect(callback)
return button
end

-- Create buttons to increase and decrease speed


local increaseButton = createButton([Link](0.5, -130, 0, 160), "Increase
Speed", [Link](0, 170, 0), [Link](255, 255, 255), function()
updateSpeedByAmount(10) end)
local decreaseButton = createButton([Link](0.5, 10, 0, 160), "Decrease
Speed", [Link](170, 0, 0), [Link](255, 255, 255), function()
updateSpeedByAmount(-10) end)

-- Minimize/Restore Button with smooth transition


local minimizeButton = [Link]("TextButton")
[Link] = [Link](0, 30, 0, 30)
[Link] = [Link](1, -40, 0, 50)
[Link] = "_"
minimizeButton.TextColor3 = [Link](255, 255, 255)
[Link] = 1
[Link] = 20
[Link] = [Link]
[Link] = mainFrame

local isMinimized = false


minimizeButton.MouseButton1Click:Connect(function()
isMinimized = not isMinimized
if isMinimized then
createTween(mainFrame, [Link](0.3), {Size = [Link](0, 350, 0,
40)})
[Link] = false
[Link] = false
[Link] = false
[Link] = false
else
createTween(mainFrame, [Link](0.3), {Size = [Link](0, 350, 0,
300)})
[Link] = true
[Link] = true
[Link] = true
[Link] = true
end
end)

-- Close button (X button) to close the UI with animation


local closeButton = [Link]("TextButton")
[Link] = [Link](0, 30, 0, 30)
[Link] = [Link](1, -40, 0, 10)
[Link] = "X"
closeButton.TextColor3 = [Link](255, 0, 0)
[Link] = 1
[Link] = 20
[Link] = [Link]
[Link] = mainFrame

closeButton.MouseButton1Click:Connect(function()
createTween(mainFrame, [Link](0.2, [Link],
[Link]), {Size = [Link](0, 350, 0, 0)})
wait(0.2)
screenGui:Destroy() -- Close the UI with animation
end)

-- Add draggable functionality with smooth dragging


local dragging = false
local dragStart = nil
local startPos = nil

[Link]:Connect(function(input)
if [Link] == [Link].MouseButton1 then
dragging = true
dragStart = [Link]
startPos = [Link]
end
end)

[Link]:Connect(function(input)
if dragging and [Link] == [Link]
then
local delta = [Link] - dragStart
[Link] = [Link]([Link], [Link] +
delta.X, [Link], [Link] + delta.Y)
end
end)

[Link]:Connect(function(input)
if [Link] == [Link].MouseButton1 then
dragging = false
end
end)
end

-- Create the UI when the player joins


createUI()

You might also like