Этот скрипт использует RemoteEvent для синхронизации анимации смерти между всеми клиентами. Он предполагает, что у вас есть анимация смерти, настроенная для персонажа.
Серверный скрипт (ServerScriptService):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathAnimationEvent = ReplicatedStorage:WaitForChild("DeathAnimationEvent") -- RemoteEvent
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoid.Died:Connect(function()
DeathAnimationEvent:FireAllClients(player) -- Запускаем анимацию смерти на всех клиентах
end)
-- Добавляем обработку столкновения со смертельным партом (если есть)
humanoidRootPart.Touched:Connect(function(hit)
local deadlyPart = workspace:FindFirstChild("DeadlyPart") -- Замените "DeadlyPart" на имя вашего смертельного парта
if hit == deadlyPart then
DeathAnimationEvent:FireAllClients(player) -- Запускаем анимацию смерти на всех клиентах
humanoid:TakeDamage(humanoid.MaxHealth) -- Убиваем игрока
end
end)
end)
end)
Клиентский скрипт (StarterPlayerScripts):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathAnimationEvent = ReplicatedStorage:WaitForChild("DeathAnimationEvent") -- RemoteEvent
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local humanoidAnimator = humanoid:GetState()
DeathAnimationEvent.OnClientEvent:Connect(function()
-- Проигрываем анимацию смерти
local animationTrack = humanoid:LoadAnimation(ReplicatedStorage:WaitForChild("DeathAnimation")) -- Замените "DeathAnimation" на имя вашей анимации смерти
animationTrack:Play()
animationTrack.Stopped:Connect(function()
--Здесь может быть добавлено что-то по завершении анимации
end)
end)
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
humanoid = character:WaitForChild("Humanoid")
humanoidAnimator = humanoid:GetState()
end)
Не забудьте:
- Создать RemoteEvent: В ReplicatedStorage создайте RemoteEvent с именем DeathAnimationEvent.
- Добавить анимацию: В ReplicatedStorage загрузите анимацию смерти (назовем её “DeathAnimation”). Убедитесь, что анимация корректно настроена в вашем персонаже.
- Настроить смертельный партикл: В workspace разместите партикл или объект, который будет обозначать смертельную зону. Замените "DeadlyPart" на его имя.
- Обработка ошибок: Добавьте обработку ошибок WaitForChild в случае, если нужные объекты не найдены.