Trying to play animation ONCE until reset

The issue I’m having is that it simply won’t play an animation because I can’t wrap my head around this code. I’ve been looking at examples and stuff for like two hours and just can’t understand how a bindable event receives a player in some examples and not in others. I’ve tried a lot of things and have gotten to the point where I feel like just deleting all the code and doing something else. Also, this is untested but I think my code might also let the animation run twice if somebody else joins and resets, but again I haven’t tested if that part is true.

Code for detecting if something is touched and then sending who touched it to the other script:
image

local e = 1
local BindableEvent = game.Workspace:WaitForChild("bindable")
function touchedChar(hit) -- Creating a function
	if hit.Parent:FindFirstChild("Humanoid") then -- Detects a humanoid inside the player's character
		if e == 1 then
			print("e")
			BindableEvent:Fire(hit.Parent)
		end
		local e = 0-- Making something happen when a part is touched
	end
end


for _,Part in ipairs(script.Parent:GetDescendants()) do
	if Part:IsA("BasePart") then
		Part.Touched:Connect(touchedChar)
	end
end

local Player = game.Players.LocalPlayer
local Char = Player.Character

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char.Humanoid.Died:Connect(function()
			local e = 1
		end)
	end)
end)

Code for running the animation and receiving the bindable event:
image

local BindableEvent = game.Workspace:WaitForChild("bindable")
local Players = game:GetService("Players")

BindableEvent.Event:Connect(function(player)
	local animation = game.Players.player.Humanoid:LoadAnimation(script.Animation)
	animation:Play()
end)	

You can’t get local player on a server script. That might be the problem

For your first code box, you’re going to need a LocalScript to use “LocalPlayer”. Else, it will not work. However, you can also change your script to work in a ServerScript too. Here’s how.

local Player = nil -- Place this at the very beginning of your script.
Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Place this inside of your touchedChar(hit) function right after your "if e == 1 then" statement.

This did work to get the name, but I’m still unsure of how to pass the name to the second script. This is what my code looks like now:

local e = 1
local Player = nil
local BindableEvent = game.Workspace:WaitForChild("bindable")
function touchedChar(hit) -- Creating a function
	if hit.Parent:FindFirstChild("Humanoid") then -- Detects a humanoid inside the player's character
		if e == 1 then
			Player = game.Players:GetPlayerFromCharacter(hit.Parent)
			print("e")
			BindableEvent:Fire(Player)
		end
		local e = 0-- Making something happen when a part is touched
	end
end


for _,Part in ipairs(script.Parent:GetDescendants()) do
	if Part:IsA("BasePart") then
		Part.Touched:Connect(touchedChar)
	end
end

local Player = game.Players.LocalPlayer
local Char = Player.Character

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char.Humanoid.Died:Connect(function()
			local e = 1
		end)
	end)
end)

and

local BindableEvent = game.Workspace:WaitForChild("bindable")

BindableEvent.Event:Connect(function(Player)
	local animation = game.Workspace.Player.Humanoid:LoadAnimation(script.Animation)
	animation:Play()
end)	

You could use remote events and pass the name through that.