Hello, I’m currently having problems with this animation script and I’d appreciate it if you can help me solve it!
THE PROBLEM
I have this script located within my ServerScriptService named DeathHandler.
I have the script set up so the player’s controls (W, A, S, D,) Would be disabled when the player dies to play one out of my four death animations. But the thing is that the player can move during this event making it sloppy, additionally, the script is also provided to disable the player’s key 1, 2, 3, and T keys since those are the player’s ability keys. The script also creates a transparent frame so the player cannot launch an attack while the animations are playing.
THE SCRIPT
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fadeTweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
local particlesTweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
local deathAnimations = {
script:WaitForChild("DeathAnimation1"),
script:WaitForChild("DeathAnimation2"),
script:WaitForChild("DeathAnimation3"),
script:WaitForChild("DeathAnimation4")
}
local function createParticles(parent)
local particles = script.DeathParticles:Clone()
particles.Rate = 0
TweenService:Create(particles, particlesTweenInfo, {Rate = 100}):Play()
particles.Parent = parent
wait(3)
TweenService:Create(particles, particlesTweenInfo, {Rate = 0}):Play()
end
local function disableControls(player)
local playerGui = player:FindFirstChild("PlayerGui")
if not playerGui then
return
end
local userInputService = game:GetService("UserInputService")
local originalInputs = {}
-- Disable player inputs
for _, inputType in pairs(Enum.UserInputType:GetEnumItems()) do
originalInputs[inputType] = userInputService.InputBegan:Connect(function(input, processed)
return processed or Enum.ContextActionResult.Sink
end)
end
wait(5)
-- Re-enable player inputs
for _, inputType in pairs(Enum.UserInputType:GetEnumItems()) do
originalInputs[inputType]:Disconnect()
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
end)
end)
ReplicatedStorage.DiedRE.OnServerEvent:Connect(function(player)
local character = player.Character
if not character or not character:FindFirstChild("Humanoid") then
return
end
local humanoid = character.Humanoid
character:WaitForChild("HumanoidRootPart").Anchored = true
local randomAnimation = deathAnimations[math.random(1, #deathAnimations)]
humanoid:LoadAnimation(randomAnimation):Play()
disableControls(player)
for _, part in pairs(character:GetDescendants()) do
if part:IsA("BasePart") or part:IsA("Decal") then
spawn(function()
TweenService:Create(part, fadeTweenInfo, {Transparency = 1}):Play()
createParticles(part)
end)
end
end
wait(5)
player:LoadCharacter()
end)
As again, I’d be really grateful if you can help solve this for me!