Animations Disappear after death

This is all in a local script the problem is that the animations revert to the unupdated animation after player death.

I have no clue why. I’ve tried putting the update function above the animation part of the script but ofcourse that didn’t work


local punchAnims = {
	'rbxassetid://17783816450',-- punch 1
	'rbxassetid://17783822840', -- punch 2
	'rbxassetid://17783832070',-- kick 1
	'rbxassetid://17783869300', -- last punch

}

local airAnims = {
	'rbxassetid://17725081405',
	'rbxassetid://17725087169',
}

local function updateAnimations(newPunchAnims, newAirAnims)
	print("Updated anims")
	punchAnims = newPunchAnims
	airAnims = newAirAnims
end

-- Listen for the server to send new animations
remote.OnClientEvent:Connect(updateAnimations)
1 Like

Can you send the server-sided script for us?

this is the data store script updated anims

~~

  • Server script (e.g., in ServerScriptService)

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Factors = require(game.ServerScriptService:WaitForChild(“Factors”)) – Adjust path as needed

– Server Script in ServerScriptService
local Players = game:GetService(“Players”)
local DataStoreService = game:GetService(“DataStoreService”)
local EquippedFactorStore = DataStoreService:GetDataStore(“EquippedFactorStore”)

– Function to load data when player joins
Players.PlayerAdded:Connect(function(player)
local equippedFactor = “BasicFactor”
local success, savedFactor = pcall(function()
return EquippedFactorStore:GetAsync(player.UserId)
end)

if success and savedFactor then
	equippedFactor = savedFactor
	print(equippedFactor)
else
	EquippedFactorStore:SetAsync(player.UserId, equippedFactor)
end

player:SetAttribute("EquippedFactor", equippedFactor)
-- Function to update animations
local function updateAnimations(character)
	local factor = equippedFactor
	if Factors[factor] then
		local punchAnims = Factors[factor].punchAnims
		local airAnims = Factors[factor].airAnims

		-- Send the updated animations to the client
		local remote = ReplicatedStorage:WaitForChild("combatnet")
		remote:FireClient(player, punchAnims, airAnims)
	end
end

-- Connect the function to when the character is added
player.CharacterAdded:Connect(updateAnimations)

-- If the player already has a character when they join
if player.Character then
	updateAnimations(player.Character)
    print(equippedFactor)
end

end)

– Function to save data when player leaves
Players.PlayerRemoving:Connect(function(player)
local equippedFactor = player:GetAttribute(“EquippedFactor”)
EquippedFactorStore:SetAsync(player.UserId, equippedFactor)
end)

– RemoteEvent to change the equipped factor
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ChangeEquippedFactor = Instance.new(“RemoteEvent”)
ChangeEquippedFactor.Name = “ChangeEquippedFactor”
ChangeEquippedFactor.Parent = ReplicatedStorage

ChangeEquippedFactor.OnServerEvent:Connect(function(player, newFactor)
player:SetAttribute(“EquippedFactor”, newFactor)
EquippedFactorStore:SetAsync(player.UserId, newFactor)
end)

~~

There’s two possible reasons for your issue:

  1. Your server script is not sending a table or data, you should try logging those to see if they’re actually sending something.
  2. You’ve already loaded the animations on the local script, making it still being displayed has the outdated versions of the animation.

When i join the game the animationsa re updates but when I die in the game they return to unupdated anims

Try changing

local factor = equippedFactor

to

local factor = player:GetAttribute("EquippedFactor")

the PlayerAdded:Connect only runs once so when you die it doesn’t update the animations again.
you can do CharacterAdded:Connect instead

CharacterAdded needs a player instance to be fired.

Another possible solution for you is to move the script from StarterCharacterScripts (or whatever parent it’s currently set) to StarterPlayerScripts.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.