local function F(q)local Z=q.Character:WaitForChild("\072\117\109\097\110\111\105\100")local s=Z:WaitForChild("\072\117\109\097\110\111\105\100\068\101\115\099\114\105\112\116\105\111\110")emoteManager:setup(q,s)local Q Q=Z.Died:Connect(function()stopEmote(q)q.CharacterAdded:Wait()F(q)Q:Disconnect()end)end local function q(q)if not q.Character then q.CharacterAdded:Wait()end F(q)end local function Z(F)stopEmote(F)emoteManager:cleanup(F.UserId)end local function s(F,q,Z)assert(onChangeEmoteLockCheck(q,Z))emoteManager:setEmoteIsLockedForPlayer(F,q,Z)end emotePlayed.OnServerEvent:Connect(startEmote)emoteStopped.OnServerEvent:Connect(stopEmote)changeEmoteLock.OnServerEvent:Connect(s)Players.PlayerAdded:Connect(q)Players.PlayerRemoving:Connect(Z)loadEmoteAssets()

local function setupEmoteManager(player)
	local humanoid = player.Character:WaitForChild("Humanoid")
	local humanoidDescription = humanoid:WaitForChild("HumanoidDescription")
	emoteManager:setup(player, humanoidDescription)

	local connection
	connection = humanoid.Died:Connect(function()
		stopEmote(player)
		player.CharacterAdded:Wait()
		setupEmoteManager(player)
		connection:Disconnect()
	end)
end

local function onPlayerAdded(player)
	if not player.Character then
		player.CharacterAdded:Wait()
	end
	setupEmoteManager(player)
end

local function onPlayerRemoving(player)
	stopEmote(player)

	emoteManager:cleanup(player.UserId)
end

local function onChangeEmoteLock(player, emoteName, isLocked)
	assert(onChangeEmoteLockCheck(emoteName, isLocked))

	emoteManager:setEmoteIsLockedForPlayer(player, emoteName, isLocked)
end

emotePlayed.OnServerEvent:Connect(startEmote)
emoteStopped.OnServerEvent:Connect(stopEmote)
changeEmoteLock.OnServerEvent:Connect(onChangeEmoteLock)

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)

loadEmoteAssets()
