How can i add a animation into this script

So i made a Ice Magic thing, when i presses Z it will spawn a ice surge. But now i wanted to add
a animation into the ice magic script that would also play when i pressed Z. But I couldn’t figure it out, how do i add it into my current script?

wait(1)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")



local Remote = ReplicatedStorage:WaitForChild("IceRemote")
local Player = game.Players.LocalPlayer
local Character = Player.Character
	
	

local CoolDown = true
local Key = "Z"




UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	local KeyPressed = Input.KeyCode
	if KeyPressed == Enum.KeyCode[Key] and CoolDown and Character then
		CoolDown = false


		Remote:FireServer()


		wait(5)
		CoolDown = true 
	end
end)

This script is a local script and its inside the StarterPack

1 Like

Here is more detail:

local Humanoid = Character.Humanoid
local anim = Humanoid:LoadAnimation(—where your animation located—)

Write it after RemoteEvent:Fire() so it have to look like this:

wait(1)

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local UserInputService = game:GetService(“UserInputService”)

local Remote = ReplicatedStorage:WaitForChild(“IceRemote”)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local anim = Humanoid:LoadAnimation()

local CoolDown = true
local Key = “Z”

UserInputService.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
local KeyPressed = Input.KeyCode
if KeyPressed == Enum.KeyCode[Key] and CoolDown and Character then
CoolDown = false

Remote:FireServer()
Animation:Play()

	wait(5)
	CoolDown = true 
end

end)

1 Like

Well i tried but it didn’t work or maybe i did a mistake. This is what i did.

local anime = Humanoid"LoadAnimation("ServerStorage") ---Server storage because
my animation was in there.

Is this correct? i checked the link u sent me but i still cant get it ;-;

No no like ServerStorage.YourAnimationName

local anime = Humanoid:LoadAnimation(“ServerStorage.AnimName”)

1 Like

image

alr i made the changes but it says Unable to cast value to object

From here, you shouldn’t put it in quotations, for starters.
Like this:

local animation = Humanoid:LoadAnimation(ServerStorage.Animation)

Also, the client cannot access server storage, I recommend you either create an Animation using something like Instance. new(), or putting it inside your script.

Like this:

local animation = Instance.new("Animation")
animation.AnimationId = --your animation id
1 Like

image

just like this?

Mhm, exactly like that.
I’d recommend setting the parent to Character for easy access but that’s up to you.

1 Like

Also, if it worked please mark the answer as the solution, helps others out with problems like yours. :wink:

1 Like

wait it does not work dont tell me all of theese cause is beacuse of my id

My way is easier if you don’t know scripting. Put animation in script

1 Like

i tried every single one of ur guy’s solution but it dosen’t work. I think its my problem lol , am having a mental breakdown lmao

Try this but place animation in script and change :LoadAnimation(change here)

1 Like

Your animation.AnimationId should be formatted like:

animation.AnimationId = "rbxassetid://6996308594" rather than just the numbers

2 Likes

wdym by place animation in script ;-; u mean animation id?

it still didnt work ahhhhhhhhhhhhhhhhhhh i had been stucked in this thing for few hours

No I mean’t in explorer. Make Parent of animation, script.

1 Like

So u mean was… Make the script as the parent of the animation? If yes ,like ;-;

1 Like

But then you have to change this :LoadAnimation(—Now where located—)

1 Like

image
this right? Or is it StarterPack.(Script name). Animation)