Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = require(game:GetService("ReplicatedStorage").SPH_Assets.GameConfig)
- if not config.firstPersonBody then return end
- local Character = script.Parent.Parent
- local RunService = game:GetService("RunService")
- local Humanoid = Character:WaitForChild("Humanoid")
- local Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso")
- local Head = Character:WaitForChild("Head")
- local ViewModelState = {
- isDead = false,
- isVehicleSeated = false,
- currentGunEquipped = nil
- }
- local function findBodyPart(model)
- for _, part in ipairs(model:GetChildren()) do
- if part:IsA("BasePart") and not (string.find(part.Name, "Arm") and ViewModelState.currentGunEquipped) then
- return part
- end
- end
- return nil
- end
- local function manageFirstPersonViewmodel(shouldHide)
- if not Torso or ViewModelState.isDead or ViewModelState.isVehicleSeated then
- return
- end
- ViewModelState.currentGunEquipped = Character:FindFirstChildWhichIsA("Tool")
- and Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("SPH_Weapon")
- local armsEnabled = Torso["Left Shoulder"].Enabled
- for _, obj in ipairs(Character:GetChildren()) do
- if obj:IsA("BasePart") then
- local shouldHidePart = (string.find(obj.Name, "Arm") and armsEnabled) or
- string.find(obj.Name, "Leg") or
- string.find(obj.Name, "Torso") or
- string.find(obj.Name, "Foot")
- obj.LocalTransparencyModifier = shouldHidePart and (shouldHide and 1 or 0) or 0
- elseif obj:IsA("Model") and obj:FindFirstChildWhichIsA("BasePart") then
- if obj.Name == "WeaponRig" then continue end
- if string.find(obj.Name, "Holster_") and not config.firstPersonHolsters then
- continue
- end
- local middlePart = obj:FindFirstChild("Middle")
- or obj:FindFirstChild("Grip")
- or findBodyPart(obj)
- if middlePart then
- middlePart.LocalTransparencyModifier = shouldHide and 1 or 0
- end
- elseif obj:IsA("Model") and obj.Name == "Armor" then
- for _, bodyPart in ipairs(obj:GetChildren()) do
- if bodyPart.Name ~= "Head" then
- for _, part in ipairs(bodyPart:GetDescendants()) do
- if part:IsA("BasePart") then
- part.LocalTransparencyModifier = shouldHide and 1 or 0
- end
- end
- end
- end
- end
- end
- end
- Humanoid.Died:Connect(function()
- ViewModelState.isDead = true
- end)
- Humanoid.Seated:Connect(function(seated, seatPart)
- ViewModelState.isVehicleSeated = seated and seatPart:IsA("VehicleSeat")
- end)
- Head:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
- manageFirstPersonViewmodel(Head.LocalTransparencyModifier == 1)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement