-- FlyAndSpeedSystem.lua
-- ใช้ใน Roblox Studio หรือในเกมของคุณเองเท่านั้น
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
local flying = false
local superSpeed = false
local flySpeed = 50
local ascendSpeed = 40
local runSpeed = 32 -- ความเร็ววิ่งเริ่มต้น (ค่า default Roblox คือ 16)
local vv, gyro
local minimized = false
-----------------------------------------------------------
-- 🧱 GUI สร้างอัตโนมัติ
-----------------------------------------------------------
local function createGui()
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "PowerGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0,240,0,200)
frame.Position = UDim2.new(0,10,0,100)
frame.BackgroundColor3 = Color3.fromRGB(25,25,25)
frame.BackgroundTransparency = 0.3
frame.BorderSizePixel = 0
frame.Parent = screenGui
local title = Instance.new("TextLabel")
title.Size = UDim2.new(1,-40,0,30)
title.Position = UDim2.new(0,10,0,5)
title.Text = "🌀 Power Panel v1.1"
title.TextColor3 = Color3.fromRGB(255,255,255)
title.TextXAlignment = Enum.TextXAlignment.Left
title.Font = Enum.Font.GothamBold
title.TextSize = 18
title.BackgroundTransparency = 1
title.Parent = frame
local minimizeBtn = Instance.new("TextButton")
minimizeBtn.Size = UDim2.new(0,30,0,30)
minimizeBtn.Position = UDim2.new(1,-35,0,5)
minimizeBtn.Text = "-"
minimizeBtn.BackgroundColor3 = Color3.fromRGB(60,60,60)
minimizeBtn.Parent = frame
local flyBtn = Instance.new("TextButton")
flyBtn.Name = "FlyToggle"
flyBtn.Size = UDim2.new(1,-20,0,40)
flyBtn.Position = UDim2.new(0,10,0,45)
flyBtn.Text = "เปิดบิน (E)"
flyBtn.Parent = frame
local flySpeedBox = Instance.new("TextBox")
flySpeedBox.Size = UDim2.new(1,-20,0,30)
flySpeedBox.Position = UDim2.new(0,10,0,90)
flySpeedBox.Text = tostring(flySpeed)
flySpeedBox.PlaceholderText = "Fly Speed"
flySpeedBox.ClearTextOnFocus = false
flySpeedBox.Parent = frame
local runBtn = Instance.new("TextButton")
runBtn.Name = "RunToggle"
runBtn.Size = UDim2.new(1,-20,0,40)
runBtn.Position = UDim2.new(0,10,0,130)
runBtn.Text = "เปิดวิ่งเร็ว (R)"
runBtn.Parent = frame
local minimize = false
minimizeBtn.MouseButton1Click:Connect(function()
if minimized then
frame:TweenSize(UDim2.new(0,240,0,200), "Out", "Quad", 0.2, true)
for _,child in ipairs(frame:GetChildren()) do
if child ~= minimizeBtn and child ~= title then
child.Visible = true
end
end
minimizeBtn.Text = "-"
minimized = false
else
frame:TweenSize(UDim2.new(0,120,0,40), "Out", "Quad", 0.2, true)
for _,child in ipairs(frame:GetChildren()) do
if child ~= minimizeBtn and child ~= title then
child.Visible = false
end
end
minimizeBtn.Text = "+"
minimized = true
end
end)
return flyBtn, flySpeedBox, runBtn
end
local flyBtn, flySpeedBox, runBtn = createGui()
-----------------------------------------------------------
-- 🚀 ฟังก์ชันบิน
-----------------------------------------------------------
local function startFlying()
if flying then return end
flying = true
humanoid.PlatformStand = false
vv = Instance.new("BodyVelocity")
vv.MaxForce = Vector3.new(1e5,1e5,1e5)
vv.P = 1250
vv.Parent = hrp
gyro = Instance.new("BodyGyro")
gyro.MaxTorque = Vector3.new(4e5,4e5,4e5)
gyro.P = 3000
gyro.CFrame = hrp.CFrame
gyro.Parent = hrp
end
local function stopFlying()
if not flying then return end
flying = false
if vv then vv:Destroy() end
if gyro then gyro:Destroy() end
humanoid.PlatformStand = false
end
-----------------------------------------------------------
-- ⚡ ฟังก์ชันวิ่งเร็ว
-----------------------------------------------------------
local function stopFlying()
if not flying then return end
flying = false
if vv then
-- ค่อย ๆ ลดความเร็วลงก่อนลบ
for i = 1, 10 do
vv.Velocity = vv.Velocity * 0.5
task.wait(0.02)
end
vv:Destroy()
end
if gyro then
gyro:Destroy()
end
-- หยุดการเคลื่อนไหวทันทีหลังจากลบ
hrp.Velocity = Vector3.zero
humanoid.PlatformStand = false
end
-----------------------------------------------------------
-- 🎮 การควบคุม
-----------------------------------------------------------
local moveVec = Vector3.zero
local upDown = 0
local function toggleSpeed(on)
if on then
humanoid.WalkSpeed = runSpeed
else
humanoid.WalkSpeed = 16
end
end
UIS.InputBegan:Connect(function(input,gp)
if gp then return end
local key = input.KeyCode
if key == Enum.KeyCode.E then
if flying then stopFlying() flyBtn.Text = "เปิดบิน (E)"
else startFlying() flyBtn.Text = "ปิดบิน (E)" end
elseif key == Enum.KeyCode.R then
superSpeed = not superSpeed
toggleSpeed(superSpeed)
runBtn.Text = superSpeed and "ปิพดวิ่งเร็ว (R)" or "เปิดวิ่งเร็ว (R)"
elseif key == Enum.KeyCode.W then moveVec = Vector3.new(moveVec.X,0,1)
elseif key == Enum.KeyCode.S then moveVec = Vector3.new(moveVec.X,0,-1)
elseif key == Enum.KeyCode.A then moveVec = Vector3.new(-1,0,moveVec.Z)
elseif key == Enum.KeyCode.D then moveVec = Vector3.new(1,0,moveVec.Z)
elseif key == Enum.KeyCode.Space then upDown = ascendSpeed
elseif key == Enum.KeyCode.LeftControl or key == Enum.KeyCode.LeftShift then upDown = -ascendSpeed
end
end)
UIS.InputEnded:Connect(function(input,gp)
if gp then return end
local key = input.KeyCode
if key == Enum.KeyCode.W or key == Enum.KeyCode.S then moveVec = Vector3.new(moveVec.X,0,0)
elseif key == Enum.KeyCode.A or key == Enum.KeyCode.D then moveVec = Vector3.new(0,0,moveVec.Z)
elseif key == Enum.KeyCode.Space or key == Enum.KeyCode.LeftControl or key == Enum.KeyCode.LeftShift then upDown = 0
end
end)
RS.RenderStepped:Connect(function()
if flying and vv and gyro then
local cam = workspace.CurrentCamera
local forward = Vector3.new(cam.CFrame.LookVector.X,0,cam.CFrame.LookVector.Z).Unit
local right = Vector3.new(cam.CFrame.RightVector.X,0,cam.CFrame.RightVector.Z).Unit
local desired = (forward * moveVec.Z + right * moveVec.X) + Vector3.new(0, upDown, 0)
if desired.Magnitude > 0 then desired = desired.Unit * flySpeed end
vv.Velocity = desired
if desired.Magnitude > 1 then
-- ล็อกทิศทางไม่ให้หมุนขึ้นลง
local flatDir = Vector3.new(desired.X, 0, desired.Z)
if flatDir.Magnitude > 0 then
gyro.CFrame = CFrame.new(hrp.Position, hrp.Position + flatDir)
end
end
end
end)
flySpeedBox.FocusLost:Connect(function()
local val = tonumber(flySpeedBox.Text)
if val and val > 0 and val <= 500 then
flySpeed = val
else
flySpeedBox.Text = tostring(flySpeed)
end
end)
flyBtn.MouseButton1Click:Connect(function()
if flying then stopFlying() flyBtn.Text = "เปิดบิน (E)"
else startFlying() flyBtn.Text = "ปิดบิน (E)" end
end)
runBtn.MouseButton1Click:Connect(function()
superSpeed = not superSpeed
toggleSpeed(superSpeed)
runBtn.Text = superSpeed and "ปิดวิ่งเร็ว (R)" or "เปิดวิ่งเร็ว (R)"
end)
-- ถ้าตัวตายหรือรีสปอนใหม่ให้รีเซ็ตค่า
player.CharacterAdded:Connect(function(c)
char = c
hrp = c:WaitForChild("HumanoidRootPart")
humanoid = c:WaitForChild("Humanoid")
stopFlying()
toggleSpeed(false)
end)