Advertisement
Rinbow

FOV Changer in Roblox

Apr 10th, 2025 (edited)
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | Gaming | 0 0
  1. local player = game.Players.LocalPlayer
  2. local camera = workspace.CurrentCamera
  3. local userInputService = game:GetService("UserInputService")
  4.  
  5. -- GUI Setup
  6. local screenGui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))
  7. screenGui.Name = "FOVSliderGui"
  8. screenGui.ResetOnSpawn = false
  9.  
  10. -- Enable UI drag behavior
  11. local function makeDraggable(frame)
  12.     local dragging = false
  13.     local dragInput, dragStart, startPos
  14.  
  15.     local function update(input)
  16.         local delta = input.Position - dragStart
  17.         frame.Position = UDim2.new(
  18.             startPos.X.Scale, startPos.X.Offset + delta.X,
  19.             startPos.Y.Scale, startPos.Y.Offset + delta.Y
  20.         )
  21.     end
  22.  
  23.     frame.InputBegan:Connect(function(input)
  24.         if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  25.             dragging = true
  26.             dragStart = input.Position
  27.             startPos = frame.Position
  28.             input.Changed:Connect(function()
  29.                 if input.UserInputState == Enum.UserInputState.End then
  30.                     dragging = false
  31.                 end
  32.             end)
  33.         end
  34.     end)
  35.  
  36.     frame.InputChanged:Connect(function(input)
  37.         if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  38.             dragInput = input
  39.         end
  40.     end)
  41.  
  42.     userInputService.InputChanged:Connect(function(input)
  43.         if input == dragInput and dragging then
  44.             update(input)
  45.         end
  46.     end)
  47. end
  48.  
  49. -- Toggle Button
  50. local toggleButton = Instance.new("TextButton", screenGui)
  51. toggleButton.Position = UDim2.new(0.9, -60, 0.05, 0)
  52. toggleButton.Size = UDim2.new(0, 60, 0, 30)
  53. toggleButton.BackgroundColor3 = Color3.fromRGB(50, 150, 255)
  54. toggleButton.TextColor3 = Color3.new(1, 1, 1)
  55. toggleButton.Text = "FOV"
  56. toggleButton.TextScaled = true
  57. makeDraggable(toggleButton)
  58.  
  59. -- FOV Frame
  60. local frame = Instance.new("Frame", screenGui)
  61. frame.Position = UDim2.new(0.35, 0, 0.9, 0)
  62. frame.Size = UDim2.new(0.3, 0, 0.08, 0)
  63. frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  64. frame.BorderSizePixel = 2
  65. frame.Visible = false
  66. makeDraggable(frame)
  67.  
  68. -- Slider
  69. local slider = Instance.new("TextButton", frame)
  70. slider.Size = UDim2.new(0.05, 0, 1, 0)
  71. slider.Position = UDim2.new((camera.FieldOfView - 1)/119, 0, 0, 0)
  72. slider.BackgroundColor3 = Color3.fromRGB(100, 200, 255)
  73. slider.Text = ""
  74.  
  75. -- FOV Label
  76. local fovLabel = Instance.new("TextLabel", frame)
  77. fovLabel.Size = UDim2.new(1, 0, 0.5, 0)
  78. fovLabel.Position = UDim2.new(0, 0, -1, 0)
  79. fovLabel.BackgroundTransparency = 1
  80. fovLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  81. fovLabel.TextScaled = true
  82. fovLabel.Text = "FOV: " .. camera.FieldOfView
  83.  
  84. -- Toggle Visibility
  85. toggleButton.MouseButton1Click:Connect(function()
  86.     frame.Visible = not frame.Visible
  87. end)
  88.  
  89. -- Slider Logic
  90. local draggingSlider = false
  91. local activeInput = nil
  92.  
  93. slider.InputBegan:Connect(function(input)
  94.     if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  95.         draggingSlider = true
  96.         activeInput = input
  97.     end
  98. end)
  99.  
  100. userInputService.InputEnded:Connect(function(input)
  101.     if input == activeInput then
  102.         draggingSlider = false
  103.         activeInput = nil
  104.     end
  105. end)
  106.  
  107. userInputService.InputChanged:Connect(function(input)
  108.     if draggingSlider and input == activeInput then
  109.         local pos = input.Position.X
  110.         local framePos = frame.AbsolutePosition.X
  111.         local frameSize = frame.AbsoluteSize.X
  112.  
  113.         local relativeX = math.clamp(pos - framePos, 0, frameSize)
  114.         local percent = relativeX / frameSize
  115.         local newFOV = math.floor(1 + (percent * 119))
  116.  
  117.         slider.Position = UDim2.new(percent, -slider.Size.X.Offset / 2, 0, 0)
  118.         camera.FieldOfView = newFOV
  119.         fovLabel.Text = "FOV: " .. newFOV
  120.     end
  121. end)
Tags: #roblox #fov
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement