Guest User

Untitled

a guest
May 26th, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. -- ⬇️  LocalScript inside StarterPlayerScripts or StarterCharacterScripts
  2. local RunService      = game:GetService("RunService")
  3. local Players         = game:GetService("Players")
  4. local player          = Players.LocalPlayer
  5. local camera          = workspace.CurrentCamera
  6.  
  7. --------------------------------------------------------------------
  8. -- CONFIG ----------------------------------------------------------
  9. --------------------------------------------------------------------
  10. local offset          = CFrame.new(0, 0, -1.5)  -- change Z to pull back / Y to raise or lower
  11. local bindName        = "CustomFPSCam"          -- render-step binding name
  12. --------------------------------------------------------------------
  13.  
  14. --------------------------------------------------------------------
  15. -- 1)  Make body parts stay visible in first-person
  16. --------------------------------------------------------------------
  17. local function forceBodyVisible(character)
  18.     for _, part in ipairs(character:GetDescendants()) do
  19.         if part:IsA("BasePart") and part.Name ~= "Head" then
  20.             part.LocalTransparencyModifier = part.Transparency
  21.             part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
  22.                 part.LocalTransparencyModifier = part.Transparency
  23.             end)
  24.         end
  25.     end
  26. end
  27.  
  28. --------------------------------------------------------------------
  29. -- 2)  Attach camera to CameraRigPart each frame
  30. --------------------------------------------------------------------
  31. local function followCamPart(character, camPart)
  32.     -- Ensure only one render-step connection is running
  33.     RunService:UnbindFromRenderStep(bindName)
  34.  
  35.     RunService:BindToRenderStep(bindName, Enum.RenderPriority.Camera.Value, function()
  36.         if not camPart.Parent then return end
  37.  
  38.         -- Desired camera frame (eye point) = camPart + offset
  39.         local desiredCF = camPart.CFrame * offset
  40.  
  41.         -- (Optional) very simple anti-clip test
  42.         local params = RaycastParams.new()
  43.         params.FilterDescendantsInstances = { character }
  44.         params.FilterType = Enum.RaycastFilterType.Blacklist
  45.         local rayDir  = desiredCF.Position - camPart.Position
  46.         local result  = workspace:Raycast(camPart.Position, rayDir, params)
  47.         if result then          -- if a wall is in the way, stop before it
  48.             desiredCF = CFrame.new(result.Position)
  49.         end
  50.  
  51.         camera.CFrame = desiredCF
  52.     end)
  53. end
  54.  
  55. --------------------------------------------------------------------
  56. -- 3)  Main setup per character spawn / respawn
  57. --------------------------------------------------------------------
  58. local function setupCharacter(character)
  59.     forceBodyVisible(character)
  60.  
  61.     -- Don’t let Humanoid.CameraOffset fight us
  62.     local hum = character:WaitForChild("Humanoid", 5)
  63.     if hum then hum.CameraOffset = Vector3.new() end
  64.  
  65.     -- Wait for your custom camera part
  66.     local camPart = character:WaitForChild("CameraRigPart", 5)
  67.     if not camPart then
  68.         warn("CameraRigPart not found in character!")
  69.         return
  70.     end
  71.  
  72.     -- Give full control to the script
  73.     camera.CameraType = Enum.CameraType.Scriptable
  74.     followCamPart(character, camPart)
  75. end
  76.  
  77. --------------------------------------------------------------------
  78. -- 4)  Hook into current & future spawns
  79. --------------------------------------------------------------------
  80. if player.Character then
  81.     setupCharacter(player.Character)
  82. end
  83. player.CharacterAdded:Connect(setupCharacter)
  84.  
  85. --------------------------------------------------------------------
  86. -- 5)  Optional: lock mouse to centre & hide cursor
  87. --------------------------------------------------------------------
  88. -- game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
  89. -- game:GetService("UserInputService").MouseIconEnabled = false
  90.  
Advertisement
Add Comment
Please, Sign In to add comment