Hello, developers. Today I was making a script that allows you too see yourself in first person. I made a code and I was wondering, why doesn’t that code work. Then I changed the whole entire code and started from scrath and made a new one. And that one worked. Here is the code that doesn’t work:
– initialize local variables
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
-- camera settings
player.CameraMaxZoomDistance = 0.5 -- force first person
camera.FieldOfView = 100
humanoid.CameraOffset = Vector3.new(0, 0, -1)
-- set and keep every body part Transparency to its real transparency
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
-- if the player steps in a vehicle
camera:GetPropertyChangedSignal("CameraSubject"):Connect(function()
if camera.CameraSubject:IsA("VehicleSeat") then
camera.CameraSubject = humanoid
end
end)
And here is the code that works:
local Player = game.Players.LocalPlayer
game:GetService("RunService").RenderStepped:connect(function()
local c = game.Workspace:FindFirstChild(Player.Name)
if c then
c["LeftFoot"].LocalTransparencyModifier = 0
c["LeftHand"].LocalTransparencyModifier = 0
c["LeftLowerArm"].LocalTransparencyModifier = 0
c["LeftLowerLeg"].LocalTransparencyModifier = 0
c["LeftUpperArm"].LocalTransparencyModifier = 0
c["LeftUpperLeg"].LocalTransparencyModifier =0
c["RightFoot"].LocalTransparencyModifier = 0
c["RightHand"].LocalTransparencyModifier = 0
c["RightLowerArm"].LocalTransparencyModifier = 0
c["RightLowerLeg"].LocalTransparencyModifier = 0
c["RightUpperArm"].LocalTransparencyModifier = 0
c["RightUpperLeg"].LocalTransparencyModifier = 0
end
end)
I just wanted to know why one of them doesn’t work and the other does work.