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)
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