local player = game:FindFirstChild("Players").LocalPlayer
local UserInputService = game:GetService("UserInputService")
local debounce = false
local hit_C = 1
local Humanoid = player.Character:FindFirstChild("Humanoid")
local animationTrack = Humanoid:LoadAnimation(script.Animation)
local function client_a (Input, IS)
if IS == true then
return
else
if Input.KeyCode == Enum.KeyCode.E then
if debounce == true then return end
debounce = true
game.ReplicatedStorage.CHit:FireServer()
if hit_C == 1 then
hit_C = 2
script.Animation.AnimationId = "rbxassetid://16166244060"
elseif hit_C == 2 then
hit_C = 1
script.Animation.AnimationId = "rbxassetid://16166263881"
elseif hit_C == 3 then
return
end
animationTrack:Play()
wait(0.2)
debounce = false
print("A")
end
end
end
UserInputService.InputBegan:Connect(client_a)
This is just a Guess, but i donât think you can change a AnimationId Tru the Client, if you can, only put A unique id on the animation object, but i think that wonât what you want, as you need multiple animations
Maybe Try Putting a RemoteEvent on ReplicatedStorage, and Manage the Animation ID changes on the server
Something like this?
local rep = game:GetService("ReplicatedStorage")
local remote = rep:WaitForChild("animchange")
remote.OnServerEvent:Connect(function(animationObject, animid)
if animationObject then
animationObject.AnimationId = "rbxassetid://"..tostring(animid)
end
end)
I believe you canât change the AnimationId after loading. LoadAnimation literally loads the current AnimationIdâs animation and creates a track from it, so it makes sense the ID canât be changed after without loading it again.
Here is some code to illustrate what to do instead:
local player = game:FindFirstChild("Players").LocalPlayer
local UserInputService = game:GetService("UserInputService")
local debounce = false
local hit_C = 1
local Humanoid = player.Character:FindFirstChild("Humanoid")
-- You need to make animation tracks for the animations
local anim1 = script.Animation:Clone()
anim1.AnimationId = "rbxassetid://16166244060"
anim1.Parent = script
local track1 = Humanoid:LoadAnimation(anim1)
local anim2 = script.Animation:Clone()
anim2.AnimationId = "rbxassetid://16166263881"
anim2.Parent = script
local track2 = Humanoid:LoadAnimation(anim2)
local function client_a (Input, IS)
if IS == true then
return
else
if Input.KeyCode == Enum.KeyCode.E then
if debounce == true then return end
debounce = true
game.ReplicatedStorage.CHit:FireServer()
if hit_C == 1 then
hit_C = 2
anim1:Play()
elseif hit_C == 2 then
hit_C = 1
anim2:Play()
elseif hit_C == 3 then
return
end
wait(0.2)
debounce = false
print("A")
end
end
end
UserInputService.InputBegan:Connect(client_a)