I want to show the Player’s body even when zooming into first person and it doesn’t work or error
I have tried using a while true loop and while (if true) do loop, both didn’t work
My script:
-- initialize local variables
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local CameraZoomDistance = tonumber(string.sub((Camera.CFrame.Position - Camera.Focus.Position).Magnitude, 1, 3))
-- if the Player steps in a vehicle
Camera:GetPropertyChangedSignal("CameraSubject"):Connect(function()
if Camera.CameraSubject:IsA("VehicleSeat") or Camera.CameraSubject:IsA("Seat") then
Camera.CameraSubject = Humanoid
end
end)
-- set and keep every body part Transparency to its real transparency
if CameraZoomDistance <= .5 then -- Do this while it is in first person
while true do
Humanoid.CameraOffset = Vector3.new(0, 0, -1)
Camera.FieldOfView = 100
for childIndex, child in pairs(Character:GetChildren()) do
if child:IsA("BasePart") and child.Name ~= "Head" then
child:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
child.LocalTransparencyModifier = child.Transparency
end)
child.LocalTransparencyModifier = child.Transparency
end
end
end
else -- if you are not in fp
Camera.FieldOfView = 70
Humanoid.CameraOffset = Vector3.new(0, 0, 0)
end
I can’t figure out what I did wrong and would be happy to recive help and learn
local RunService = game:GetService("RunService");
local Player = game.Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Camera = game.Workspace.CurrentCamera;
local Head = Character:WaitForChild("Head");
local FPMaximumDistance = 0.6; -- For scalability, but keep it at 0.6 since it is the right distance.
local FirstPersonLocalTransparency = 0;
local ThirdPresonLocalTransparency = 0;
local function SetCharacterLocalTransparency(transparency)
for i,v in pairs(Character:GetChildren()) do
if (v:IsA("BasePart")) then -- Only baseparts have a LocalTransparencyModifier property.
v.LocalTransparencyModifier = transparency;
end
end
end
RunService.RenderStepped:Connect(function()
local isfirstperson = (Head.CFrame.Position - Camera.CFrame.Position).Magnitude < FPMaximumDistance; -- Determine wether we are in first person
if (isfirstperson) then
SetCharacterLocalTransparency(FirstPersonLocalTransparency);
else
SetCharacterLocalTransparency(ThirdPresonLocalTransparency);
end
end)
I’m glad you’re willing to learn, so just take a quick minute for a few remarks I would like to point out.
This solution should be run in a LocalScript.
I’ve left some variables to help you customize a few things. Although I don’t recommend you changing the FPMaximumDistance variable since 0.6 is by far the proper number to determine a first person zoom.
You can change the FirstPersonLocalTransparency to be any number from (0 - 1).
0 = Fully opaque (Fully visible)
1 = Fully transparent
I’m running the code check through the RunService with a function binded to RenderStepped. This code will be run every frame of the RenderStepped Update call. (As fast as the client’s machine can update frames) It gives the quickest result and since we are dealing with camera movement, it is reasonable. Since RenderStepped updates at the start of every frame, it’s almost an instant transparency swap.
For more information on RenderStepped:
In the SetCharacterLocalTransparency(transparency) function, it goes through all of the players BaseParts (Anything that is considered a BasePart such as a Part) and sets the LocalTransparencyModifier according to the passed in value. You can whitelist parts on your own terms if need be. (You will need to implement that logic)
Hopefully you can learn a few new things from this!
Best of luck!
Pardon for bumping, but I’ve been having this same problem, tried out the script, and it solved it. Unfortunately, the head still shows. If you want to exclude the head, or show accessories, try replacing this…
local function SetCharacterLocalTransparency(transparency)
for i,v in pairs(Character:GetChildren()) do
if (v:IsA("BasePart")) then -- Only baseparts have a LocalTransparencyModifier property.
v.LocalTransparencyModifier = transparency;
end
end
end
…with this…
local function SetCharacterLocalTransparency(transparency)
for i,v in pairs(Character:GetChildren()) do
if (v:IsA("BasePart")) and (v.Name ~= "Head") then -- Only baseparts have a LocalTransparencyModifier property.
v.LocalTransparencyModifier = transparency;
elseif (v:IsA("Accessory")) and (v:FindFirstChild("Handle")) then
if v.Handle:FindFirstChild("AccessoryWeld").Part1 == Head then
else
v:FindFirstChild("Handle").LocalTransparencyModifier = transparency;
end
end
end
end
Camera offset… make the camera focus on something else… make a part welded to the players head which looks behind them, and cframe the camera to match the cframe with that part…
Set the head’s transparency to 1 and also if can see the tongue, it would hide the parts as well so don’t worry about it.
-- Script Example --
local RunService = game:GetService("RunService");
local Player = game.Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Camera = game.Workspace.CurrentCamera;
local Head = Character:WaitForChild("Head");
local FPMaximumDistance = 0.6; -- For scalability, but keep it at 0.6 since it is the right distance.
local FirstPersonLocalTransparency = 0;
local ThirdPresonLocalTransparency = 0;
local function SetCharacterLocalTransparency(transparency)
for i,v in pairs(Character:GetChildren()) do
if (v:IsA("BasePart")) then -- Only baseparts have a LocalTransparencyModifier property.
v.LocalTransparencyModifier = transparency;
end
end
end
RunService.RenderStepped:Connect(function()
local isfirstperson = (Head.CFrame.Position - Camera.CFrame.Position).Magnitude < FPMaximumDistance; -- Determine wether we are in first person
if (isfirstperson) then
SetCharacterLocalTransparency(FirstPersonLocalTransparency);
else
SetCharacterLocalTransparency(ThirdPresonLocalTransparency);
end
-----------------------------(( MAIN SCRIPT ))-----------------------------
for i, head in pairs(Character:GetDescendants()) do
if head.Name == "Head" then
head.Transparency = 1
end
end
-----------------------------(( MAIN SCRIPT ))-----------------------------
end)