Advertisement
Lazzzycat1

FPScam33

Jan 2nd, 2025 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | Gaming | 0 0
  1. local config = require(game:GetService("ReplicatedStorage").SPH_Assets.GameConfig)
  2. if not config.firstPersonBody then return end
  3.  
  4. local Character = script.Parent.Parent
  5. local RunService = game:GetService("RunService")
  6. local Humanoid = Character:WaitForChild("Humanoid")
  7. local Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso")
  8. local Head = Character:WaitForChild("Head")
  9.  
  10. local ViewModelState = {
  11.     isDead = false,
  12.     isVehicleSeated = false,
  13.     currentGunEquipped = nil
  14. }
  15.  
  16. local function findBodyPart(model)
  17.     for _, part in ipairs(model:GetChildren()) do
  18.         if part:IsA("BasePart") and not (string.find(part.Name, "Arm") and ViewModelState.currentGunEquipped) then
  19.             return part
  20.         end
  21.     end
  22.     return nil
  23. end
  24.  
  25. local function manageFirstPersonViewmodel(shouldHide)
  26.     if not Torso or ViewModelState.isDead or ViewModelState.isVehicleSeated then
  27.         return
  28.     end
  29.    
  30.     ViewModelState.currentGunEquipped = Character:FindFirstChildWhichIsA("Tool")
  31.         and Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("SPH_Weapon")
  32.  
  33.     local armsEnabled = Torso["Left Shoulder"].Enabled
  34.  
  35.     for _, obj in ipairs(Character:GetChildren()) do
  36.         if obj:IsA("BasePart") then
  37.             local shouldHidePart = (string.find(obj.Name, "Arm") and armsEnabled) or
  38.                 string.find(obj.Name, "Leg") or
  39.                 string.find(obj.Name, "Torso") or
  40.                 string.find(obj.Name, "Foot")
  41.             obj.LocalTransparencyModifier = shouldHidePart and (shouldHide and 1 or 0) or 0
  42.  
  43.         elseif obj:IsA("Model") and obj:FindFirstChildWhichIsA("BasePart") then
  44.             if obj.Name == "WeaponRig" then continue end
  45.  
  46.             if string.find(obj.Name, "Holster_") and not config.firstPersonHolsters then
  47.                 continue
  48.             end
  49.  
  50.             local middlePart = obj:FindFirstChild("Middle")
  51.                 or obj:FindFirstChild("Grip")
  52.                 or findBodyPart(obj)
  53.  
  54.             if middlePart then
  55.                 middlePart.LocalTransparencyModifier = shouldHide and 1 or 0
  56.             end
  57.  
  58.         elseif obj:IsA("Model") and obj.Name == "Armor" then
  59.             for _, bodyPart in ipairs(obj:GetChildren()) do
  60.                 if bodyPart.Name ~= "Head" then
  61.                     for _, part in ipairs(bodyPart:GetDescendants()) do
  62.                         if part:IsA("BasePart") then
  63.                             part.LocalTransparencyModifier = shouldHide and 1 or 0
  64.                         end
  65.                     end
  66.                 end
  67.             end
  68.         end
  69.     end
  70. end
  71.  
  72. Humanoid.Died:Connect(function()
  73.     ViewModelState.isDead = true
  74. end)
  75.  
  76. Humanoid.Seated:Connect(function(seated, seatPart)
  77.     ViewModelState.isVehicleSeated = seated and seatPart:IsA("VehicleSeat")
  78. end)
  79.  
  80. Head:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
  81.     manageFirstPersonViewmodel(Head.LocalTransparencyModifier == 1)
  82. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement