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)
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.
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
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)
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)