How To Make This Killcam Unattach?

Hey guys, I am making a killcam, but I just can’t figure out how to make it stop after a couple seconds.

local player = script.Parent.Parent 
repeat wait() until Workspace.CurrentCamera 
repeat wait() until player.Character 
local C = Workspace.CurrentCamera 

C.CameraSubject = player.Character.Humanoid -- Reset the CameraSubject to the humanoid
C.CameraType = "Custom" -- Reset the CameraType to Custom

player.Character.Humanoid.Died:connect(function() 
    local killer = player.Character.Humanoid:findFirstChild("creator") 
    if killer then 
        for _,v in pairs(script.Parent:children()) do 
            if v.Name ~= "KillCam" then 
                v:remove() 
            end 
        end 
        local G = Instance.new("ScreenGui",player.PlayerGui) 
        local F1 = Instance.new("Frame",G) 
        local F2 = Instance.new("Frame",G) 
        F1.BackgroundColor3 = Color3.new(0/255,0/255,0/255) 
        F2.BackgroundColor3 = Color3.new(0/255,0/255,0/255) 
        F1.Size = UDim2.new(1,0,0,0) F2.Size = UDim2.new(1,0,0,0) 
        F2.Position = UDim2.new(0,0,.85,0)
        Spawn(function() 
            for i=1, 15 do 
                wait() 
                F1.Size = F1.Size + UDim2.new(0,0,.01,0) 
                F2.Size = F2.Size + UDim2.new(0,0,.01,0) 
                F2.Position = UDim2.new(0,0,1-(i*.01),0) 
            end 
        end) 
        C.CameraSubject = killer.Value.Character 
        C.CameraType = "Attach"
    end 
end)

Thanks!

1 Like

To set the CameraType, you need to use the CameraType Enum, not just a string.

For example:

C.CameraType = Enum.CameraType.Custom

Also, make sure the LocalScript is inside StarterPlayerScripts or somewhere where it will be regenerated. This way, the script will be restarted when the character respawns.

2 Likes

I mean, The killcam works but it doesn’t unattach

1 Like

Where is the script at? It should reset automatically once you respawn if it’s in StarterCharacterScripts.

1 Like

Its in starter GUI. 30 charsacters

1 Like

Try moving the script to StarterPlayer>StarterCharacterScripts, that way it’ll run each time you respawn. These lines reset the camera for you, and they run as soon as the script does so it’ll run once you respawn.

C.CameraSubject = player.Character.Humanoid -- Reset the CameraSubject to the humanoid
C.CameraType = "Custom" -- Reset the CameraType to Custom
1 Like

Technically the PlayerGui should be reloaded with the character too, but this is worth a shot.

2 Likes

Depends, if it’s in a ScreenGui with ResetOnSpawn set to false it won’t re-run.

1 Like

Hmmm, where exactly in my lines of code would I place that?

1 Like

I was explaining what it does, it’s already in your code.

2 Likes

Change “Custom” to Enum.CameraType.Custom. That property accepts a Enum value.

1 Like

Ok, I tried it but this time the killcam doesn’t even work, also @sean21307 Why do the players always spawn on the same spawn point? - #2 by sean21307 it didn’t work :frowning:

1 Like

Oops, try changing the player variable to this
local player = game:GetService("Players").LocalPlayer.

You’ll also have to change this section

for _,v in pairs(player.PlayerGui:GetChildren()) do 
    if v.Name ~= "KillCam" then 
        v:Destroy() 
    end 
end 
1 Like

Setting CameraType through a string might not be preferable, but it’s fine and works.

2 Likes

I may have found the root of the problem, the weapon is not giving the creator tag and killer tag.

1 Like

Wasn’t it working before though?

2 Likes

Yes, but someone may have tinkered with the script as the damage script isn’t there anymore… hold up, lemme check summat

Is there anything wrong with this script-

local secondhumanoid = game.Players.LocalPlayer
--Sword script?

--Define your player
local plr = game.Players.LocalPlayer
local killer = script.Parent.Parent.Parent.Parent
--Whenever the handle touches someone
script.Parent.Touched:Connect(function(hit)
    --Check to make sure it's a player
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        --Create the tag, place it in their Humanoid
        local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
        tag.Name = 'creator'
        --Make the value your player instance
        tag.Value = killer
        --To be fair, make the tag expire.. so someone that you hit 10 minutes ago doesn't reward you a KO
        wait(10)
        tag:Destroy()
    end
end)
--End of what Karoleq needs to check out
function onTouched(hit)
        local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
                human.Health = human.Health - 10 -- Change the amount to change the damage dealt on humanoid.
        end
end
script.Parent.Touched:Connect(onTouched)
if script.Parent.CanAttack.Value == true then

    script.Parent.CanAttack.Value = true

    secondhumanoid.Humanoid:TakeDamage(10)

end
script.Parent.Blade.Touched:Connect(function(touch)
 
    if script.Parent.CanAttack.Value == true then
 
        local humanoid = touch.Parent:FindFirstChild("Humanoid")
 
        if not touch.Parent:FindFirstChild("Humanoid") then 
 
            humanoid = touch.Parent.Parent:FindFirstChild("Humanoid")
 
        end
 
        if humanoid.Name ~= "Humanoid" then return end
        
        script.Parent.CanAttack.Value = false
 
        humanoid:TakeDamage(20)
        
        if humanoid.Health < 1 then
            
            local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
            plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
            
        end
        
        wait(1)
        
        script.Parent.CanAttack.Value = true
    end
end)


@sean21307

1 Like

Many things, try replacing it with this. Make sure it’s a server script.

local original_player = script.Parent
local hitTable = {}

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if plr and hum then
		if not hitTable[hum] or tick() - hitTable[hum] > .5 then
			hitTable[hum] = tick()
			hum:TakeDamage(10)
        	local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
	        tag.Name = 'creator'
			tag.Value = original_player
			tag.Parent = hit.Parent.Humanoid
        	wait(10)
			tag:Destroy()
		end
    end
end)

1 Like