Playing animation before death

So i’m trying to code this so that it’ll kill all players and play an animation before it kills them but they die before the animation plays

local Snap = script.Animation
local Workspace = game.Workspace
local descendant = game.Workspace:GetDescendants()

local function Plague()
if descendant:IsA("Humanoid") then
		local humanoid = descendant
	Snap:Play()
	wait(4)
	humanoid.Character.Humanoid:TakeDamage(100)
	end
	end
2 Likes

Use Animation.Completed:Connect(function() for when you want them to die after the animation.

Also, it might wait four seconds after the “Snap” animation is done, so if it does just remove that wait(4) :slight_smile:

so like this?

local function Plague()
if descendant:IsA("Humanoid") then
		local humanoid = descendant
	Snap:Play()
	end	
		
		Snap.Completed:Connect(function()

	descendant.Character.Humanoid:TakeDamage(100)
	end
	)

As ript said, you should use Animation.Completed but I don’t know here it is your script but you should put it in the server script service and there you go the code:

game.Players.PlayerAdded:Connect(function(player)
	local Snap = script.Animation
	local Workspace = game.Workspace
	local descendant = game.Workspace:GetDescendants()
	
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local hum = v:FindFirstChild("Humanoid")
			local anim = hum:LoadAnimation(Snap)
			anim:Play()
			anim.Completed:Connect(function()
				hum:TakeDamage(100)
				print(hum.Parent.Name.. " died.")
			end)
		end
	end
end)

I hope this can help you

it’s supposed to be a function that will be ran though

Lol you can use the term “workspace” to refer to game.Workspace, no variable is required.But yeah that’s the approach.

true dat, my bad, im sorry lol

Then you can put his code into a function like

Sorry about the wacky formatting but yeah

local function plage()
	local Snap = script.Animation

	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local hum = v:FindFirstChild("Humanoid")
			local anim = hum:LoadAnimation(Snap)
			anim:Play()
			anim.Completed:Connect(function()
				hum:TakeDamage(100)
				print(hum.Parent.Name.. " died.")
			end)
		end
	end
end

I got this error. (Also changed Function name to Neck)

image

show me the script and i’ll be sure about it but basically you should change the “anim” for the “Snap” varible

--SCRIPT WRITTEN BY CLEETUSCHAN--
local Players = game.Players:GetChildren()

local Workspace = game.Workspace
local descendant = game.Workspace:GetDescendants()


local function Neck()
	local Snap = script.Animation

	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local hum = v:FindFirstChild("Humanoid")
			local anim = hum:LoadAnimation(Snap)
			anim:Play()
			anim.Completed:Connect(function()
				hum:TakeDamage(100)
				print(hum.Parent.Name.. " died.")
			end)
		end
	end
end



game.Players.PlayerAdded:Connect(function(player)
  player.Chatted:Connect(function(msg)
		if (msg == "May you rest in peace.") then 
		Neck()
		end
end)
end)

yeah that’s it you must change the variables ig but i’ll test it out too

1 Like

actually it is not completed, it is Stopped,

local function neck()
	local Snap = script.Animation

	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local hum = v:FindFirstChild("Humanoid")
			local anim = hum:LoadAnimation(Snap)
			anim:Play()
			anim.Stopped:Connect(function()
				hum:TakeDamage(100)
				print(hum.Parent.Name.. " died.")
			end)
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if (msg == "May you rest in peace.") then 
			neck()
		end
	end)
end)
1 Like

It’s still not working right. I just die and it doesn’t play the animation. No errors either

--SCRIPT WRITTEN BY CLEETUSCHAN--
local Players = game.Players:GetChildren()

local Workspace = game.Workspace
local descendant = game.Workspace:GetDescendants()


local function Neck()
	local Snap = script.Animation

	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local hum = v:FindFirstChild("Humanoid")
			local anim = hum:LoadAnimation(Snap)
			anim:Play()
			anim.Stopped:Connect(function()
				hum:TakeDamage(100)
				print(hum.Parent.Name.. " died.")
			end)
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if (msg == "May you rest in peace.") then 
			Neck()
		end
	end)
end)



game.Players.PlayerAdded:Connect(function(player)
  player.Chatted:Connect(function(msg)
		if (msg == "May you rest in peace.") then 
		Neck()
		end
end)
end)

well I tested it out and it worked, can you make a gif to show us what happen?

1 Like

you also made 2 player.Chatted events with the same msg…

1 Like

wait i may see the problem besides that

1 Like