My game is a first person shooter and i made it so th eplayer is able to see their body while in first person. However an issue arises as to when a player dies they cant see their body anymore even if they hold a gun they cant see their arms or anything however when i remvoed lock first person. When the issue happens and i slightly zoom out the players body appears again and when i zoom in it fades out once more.
#First Person Body Disappear after death
1 messages · Page 1 of 1 (latest)
this is my code for being able to see your body in first person
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local renderConnection
local function setupCharacter(character)
if renderConnection then
renderConnection:Disconnect()
end
local humanoid = character:WaitForChild("Humanoid")
camera.CameraSubject = humanoid
camera.CameraType = Enum.CameraType.Custom
for _, part in ipairs(character:GetChildren()) do
if part:IsA("BasePart") and part.Name ~= "Head" then
part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
part.LocalTransparencyModifier = part.Transparency
end)
part.LocalTransparencyModifier = part.Transparency
end
end
renderConnection = RunService.RenderStepped:Connect(function()
local head = character:FindFirstChild("Head")
if head then
local rayOrigin = head.Position
local rayDirection = head.CFrame.LookVector * 2 -- Forward
local ray = Ray.new(rayOrigin, rayDirection)
local ignoreList = {character}
local hitPart, hitPosition = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if hitPart then
local distance = (head.Position - hitPosition).Magnitude
if distance < 1 then distance = 1 end
humanoid.CameraOffset = Vector3.new(0, -0.75, -distance)
else
humanoid.CameraOffset = Vector3.new(0, -0.8, -1.8)
end
end
end)
end
if player.Character then
setupCharacter(player.Character)
end
player.CharacterAdded:Connect(setupCharacter)
its one of my first projects so i made this looking around online and on pages since i am not too familiar with roblox studio yet or lua
where is the script in?
its a local script in startercharacterscripts
whats the if player.Character then
setupCharacter(player.Character)
end used for?
i tried adding it so it would immdietly setup the player as i wasnt sure if it was a loading issue but now that i know its pretty much useless as to my knowledge
umm
the loading issue might be because youre not waiting for the service to load
use game:GetService("Players").LocalPlayer
well it isnt a laoding issue anymore as i know the player body and everything is there i just need to zoom out to see it as its like transparent ig? when i respawn and in first person
this is how it looks when i respawn and im in first person
when i start to zoom out the body starts to fade in
however when the game starts this isnt an issue as i am in first person and can see my body
** You are now Level 2! **
is there any errors printing
** You are now Level 4! **
yea try seeing where it works and where it doesnt
i debugged it and everything prints as it should it finds the correct parts when a player respawns and the offset isnt any different as to when they dont die
remove this
if player.Character then
setupCharacter(player.Character)
end
and move the script to StarterPlayerScripts instead
so i removed that part however now fully once i join i cant see my body until i zoom out