How to make Kill cam

Hi, I’m trying to make a killer cam, which worked at first, but now is no longer.

Here is the script:

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local imalabel = script.Parent.Frame.ImageLabel
local texlabel = script.Parent.Frame.TextLabel

hum.Died:Connect(function(killed)
	local killer = char.Humanoid:FindFirstChild("creator")
	
	print(killer)
	
	if killer.Value then
		
		local killerChar = killer.Value.Character
		local killerName = killer.Value.Name
		local killerId = killer.Value.UserId
		local image, isReady = game.Players:GetUserThumbnailAsync(killerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size180x180)
		
		cam.CameraSubject = killerChar.Humanoid
		script.Parent.Frame.Visible = true
		imalabel.Image = image
		texlabel.Text = killerName
		wait(10)
		cam.CameraSubject = hum
		script.Parent.Frame.Visible = false
		
	end
end)

This script is in a local script in the gui.

Everytime I play, then I kill a player, on the player’s screen there is an error at if killer.Value then. As you can see I also tried to see what was wrong by printing the killer value but it printed nil. Can you please help me? I have no idea why the script is no longer working. Thanks!

12 Likes

Are you sure char.Humanoid.creator is being set properly by the weapon responsible for the death of your player?

6 Likes

Well when the script used to work before, I didn’t use another weapon. But then the weapon didn’t kill the player anymore, so I changed it and now the kill cam doesn’t work. I’m completely confused.

4 Likes

Drop the code for your weapon’s damaging, I’ll check over it

4 Likes

This is the current sword’s damage script. I was previously using the Classic Sword model by Roblox

script.Parent.blade.Touched:connect(function(p)
	if script.Parent.CanDamage.Value == true then 
		if p.Parent:FindFirstChild("Humanoid") then
   p.Parent.Humanoid:TakeDamage(35) 
			script.Parent.CanDamage.Value = false 
			end
      end 
 end) 
3 Likes

Okay! I think I see the problem.
Essentially, what’s happening is that it’s not marking the character as being killed from the player responsible. This is a simple fix, so I’ll do it for you:
If it doesn’t work, lmk!!

script.Parent.blade.Touched:connect(function(p)
	if script.Parent.CanDamage.Value == true then 
		if p.Parent:FindFirstChild("Humanoid") then
		-- checking that this blow would kill
			if p.Parent.Humanoid.Health - 35 <= 0 then
				-- ensuring it's a player that killed you.
				local Player = game.Players:GetPlayerFromCharacter(p.Parent)
				if Player then
					local CreateValue = Instance.new("ObjectValue")
					CreateValue.Name = "creator"
					CreateValue.Parent = p.Parent.Humanoid
					CreateValue.Value = Player
				end
		
			end
   p.Parent.Humanoid:TakeDamage(35) 
			script.Parent.CanDamage.Value = false 
			end
      end 
 end) 
3 Likes

The damage kinda works, I tried to upload a video of it but it didn’t let me fully kill the player, so the kill cam couldn’t start.

4 Likes

Fixed @returnedbydeath code.

script.Parent.blade.Touched:connect(function(p)
	if script.Parent.CanDamage.Value == true then 
		if p.Parent:FindFirstChild("Humanoid") then
		-- checking that this blow would kill
			if p.Parent.Humanoid.Health < 35 then
				-- ensuring it's a player that killed you.
				local Player = game.Players:GetPlayerFromCharacter(p.Parent)
				if Player then
					local CreateValue = Instance.new("ObjectValue")
					CreateValue.Name = "creator"
					CreateValue.Parent = p.Parent.Humanoid
					CreateValue.Value = Player
				end
				p.Parent.Humanoid:TakeDamage(35) 
		
			end
   p.Parent.Humanoid:TakeDamage(35) 
			script.Parent.CanDamage.Value = false 
			end
      end 
 end) 

I would also suggest doing
if killer and killer.Value then

5 Likes

Now this happens now, it could be the killer cam script now.

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local imalabel = script.Parent.Frame.ImageLabel
local texlabel = script.Parent.Frame.TextLabel

hum.Died:Connect(function(killed)
	local killer = char.Humanoid:FindFirstChild("creator")
		
	if killer or killer.Value then
		
		local killerChar = killer.Value.Character
		local killerName = killer.Value.Name
		local killerId = killer.Value.UserId
		local image, isReady = game.Players:GetUserThumbnailAsync(killerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size180x180)
		
		cam.CameraSubject = killerChar.Humanoid
		script.Parent.Frame.Visible = true
		imalabel.Image = image
		texlabel.Text = killerName
		wait(10)
		cam.CameraSubject = hum
		script.Parent.Frame.Visible = false
		
	end
end)
2 Likes

Firstly, you would need to delay the time for character respawns making it take more time in order to respawn. Secondly, you would just set the camera subject to the humanoid that damaged the character last.

6 Likes

Thanks guys! I couldn’t have gotten it without you’re help!

4 Likes

Actually after I messed around with some scripts, I realized that the spectate script worked, it was just that one of my scripts had game.StarterGui.ResetPlayerGuiOnSpawn = false messed it up. Thanks again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.