Alright so, I am doing an FPS project. Meaning its an FirstPersonShooter game. But it has a unique feature. When the team is police, you will be in First Person mode. If the team is Inmates, you will play in Third Person mode. So basically I am coding when a player in the police team dies.
So what I am currently doing is when I die, I want the camera the zoom out, without having to use the scroll wheel to see the body. Meaning the camera will zoom out automatically showing the dead body.
So the problem is I can’t think of a way to make the in-game camera (?) to zoom out without having to actually use the mouse wheel to see the dead body. You know, just like in other FPS games like counter-strike. When you die, the camera zooms out of you and it shows your body collapsing. You know what I mean? Anyways, I’ll be showing the code.
Here is the code for handling FPS Arms Framework and Police Death:
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local RunService = game:GetService("RunService")
-- 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--]]
function RenderStepped()
for index,bodyPart in pairs(character:GetChildren()) do
if string.match(bodyPart.Name, "Arm") or string.match(bodyPart.Name, "Hand") then
bodyPart.LocalTransparencyModifier = 0
end
end
end
RunService.RenderStepped:Connect(RenderStepped)
humanoid.Died:Connect(function()
humanoid.CameraOffset = Vector3.new(0, 0, 0)
camera.FieldOfView = 70
player.CameraMinZoomDistance = 15
player.CameraMaxZoomDistance = 15
end)
Note: Ignore the commented for loop on the top. I made an RenderStepped function to only see arms not the whole body.
So a screenshot of what happenes when I get killed:
As you can see, i still really need to use the mouse scroll wheel. Even thought I set the Minimum and Maximum camera zoom to 15 just to make it zoom out a little far. But still, I literally have to still use the scroll wheel.
I don’t know what is wrong with my code. Maybe some bug? I tried CFraming the current camera by workspace aka “Camera” when in-game studio. Somebody help please! The problem is really confusing of which camera is for using the scroll wheel. I want the camera to zoom out everytime I die as a police.
To make it clear, first I run a RenderStepped function that is for the framework. Showing the arms. Zooming all the way in. Setting Minimum/Maximum Camera Zoom Distance to 0.5, so when the humanoid gets the health to zero, I will tell the script to set Min/Max Camera Zoom Distance to 15. So it will force zoom out.
So if any of you have any ideas, suggestions, fixes to suggest to me, just reply below! Thanks in advance!