I’ve been trying to make a script which shows the torso and legs visible in first person, and i haven’t gotten any results. Originally it was a first person body script, but i scraped it since i made a view-model for the movement in first person. But, i tried editing my script but i got no luck.
local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")
char.Humanoid.CameraOffset = Vector3.new(0, 0, -5)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Head" then
v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = v.Transparency
end)
v.LocalTransparencyModifier = v.Transparency
end
end
RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if hit then
char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
else
char.Humanoid.CameraOffset = Vector3.new(0, 0, -2)
end
end)
and here’s my try at editing it:
local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")
char.Humanoid.CameraOffset = Vector3.new(0, 0, -5)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Head" or "Arm" then
v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = v.Transparency
end)
v.LocalTransparencyModifier = v.Transparency
end
end
RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if hit then
char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
else
char.Humanoid.CameraOffset = Vector3.new(0, 0, -2)
end
end)
When i didn’t edit the script, it worked completely fine.
But, when i edited the script to make it work, it didn’t show anything.
If i could get some help, i would really appreciate it!
The problem might have to do with the character not loading. Here is the code:
local RunService = game:GetService("RunService");
local player = game.Players.LocalPlayer;
task.wait(2)
local character = player.Character character = player.Character character = player.Character
if character then
character = player.Character
else
character = player.Character
end
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")) and v.Name ~= "Right Arm" or "Left Arm" 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)
Here I have replaced
local Character = Player.Character or Player.CharacterAdded:Wait();
with
task.wait(2)
local character = player.Character character = player.Character character = player.Character
if character then
character = player.Character
else
character = player.Character
end
This ensures that local character = player.Character after the character has loaded in.
Also be sure to make it a localscript.