Hey, helpers!
I have this script that basically shows an image that says "Game Over" when a player dies. However, since my current round script uses resetting to move the players around the map, I only want this script to work when a player is killed by the NPC. I tried using function and it gave me a bunch of errors. Here is the script (that works) without the NPC detection:
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
gameover = Instance.new("ScreenGui")
gameover.Parent = player.PlayerGui
gameover.Name = "GameOverGui"
image = Instance.new("ImageLabel")
image.Parent = gameover
image.Name = "GameOverImage"
image.BackgroundTransparency = 1
image.Image = "http://www.roblox.com/asset/?id=777253063"
image.Size = UDim2.new(1,0,1,0)
end)
end)
end)
Here is the one that doesn't work (with detection)
function touched(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil then
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
gameover = Instance.new("ScreenGui")
gameover.Parent = player.PlayerGui
gameover.Name = "GameOverGui"
image = Instance.new("ImageLabel")
image.Parent = gameover
image.Name = "GameOverImage"
image.BackgroundTransparency = 1
image.Image = "http://www.roblox.com/asset/?id=777253063"
image.Size = UDim2.new(1,0,1,0)
end)
end)
end)

3 comments
Edit your post and paste the error that gives you.
I have some few scripts that do something when they die. But the hit function isn't in the humanoid / local humanoid
& should there not be two or some more "end"?