Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you get this Script that Performs after a Player's Death to Work?

So the script is supposed to show a GUI and place the camera focus on the killer of a player.

The script only shows the GUI, but doesn't change the camera focus.

The only thing output gave me was this: "Workspace.KillCam:1: attempt to index field 'Instance' (a nil value)"

Can someone please help me?

Here's the script:

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
wait()
Character.Humanoid.Died:connect(function()
local Tag = Character.Humanoid:FindFirstChild("creator")
if Tag ~= nil then 
if Tag.Value ~= nil then 
if Tag.Value.Parent ~= nil then 
if Tag.Value.Character ~= nil then 
local Gui = script.KillGui:Clone()
Gui.TopFrame.TextLabel.Text = "You were Killed by " .. string.upper(Tag.Value.Name)
Gui.Parent = Player.PlayerGui
game.Workspace.CurrentCamera.CameraSubject = game.Workspace[Tag.Value].Character.Humanoid
game.Workspace.CurrentCamera = Enum.CameraType.Track
end
end
end
end
end)
end)
end)

1 answer

The script is a bit messy, and tries to do some stuff that doesn't exist (Tag.Value.Name, Tag.Value.Character?). Along with that, you're taking way too many precautions which can slow down the script overall.

Here's the fixed thing:

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
Character.Humanoid.Died:connect(function() --Wait is unnecessary
local Tag = Character.Humanoid:FindFirstChild("creator")
if Tag ~= nil then --You're taking way too many precautions for a StringValue holder
local Gui = script.KillGui:Clone()
Gui.Parent = Player.PlayerGui --Put this first
Gui.TopFrame.TextLabel.Text = "You were Killed by " .. string.upper(Tag.Value)
game.Workspace.CurrentCamera.CameraSubject = game.Workspace[Tag.Value].Humanoid --You're referring to the subject via `Workspace`, `Character` is not for there
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Track --You're refering to the `Camera` itself, not the `CameraType`.
end
end)
end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.