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