Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Animation script with hotkey is failing. Why is this happening?

I have tried a script where I press a key and it makes an animation happen. For some reason, the script only works when I jump. This is a Server Script.

local repstorage = game:WaitForChild("ReplicatedStorage")
local Remote = repstorage:WaitForChild("IceStart")


Remote.OnServerEvent:connect(function(player)
    
    local char = player.Character
    script.Dmg.Player.Value = player.Name
    local folder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace)
    folder.Name = "DebrisFolder"

local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://000"
local Move = char.Humanoid:LoadAnimation(Anim)
Move:Play()

local position = Instance.new("BodyVelocity",char.HumanoidRootPart)
position.MaxForce = Vector3.new(99999999999999,99999999999999,99999999999999)
position.P = 300
position.Velocity = char.HumanoidRootPart.CFrame.LookVector * 1
game.Debris:AddItem(position,2)

There is also another script that connects to make that work.

local repstorage = game:WaitForChild("ReplicatedStorage")
local Remote = repstorage:WaitForChild("IceStart")

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
cool = true

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "z" then
    if cool ~= true then return end
    cool = false
    
    Remote:FireServer()
    
    
    
    
    
    
    
    
    wait(5)
    cool = true
    end
end)

3 comments

0

keydown is decaperated

0

Thanks. keyDown now or just keydown

0

no use UserInputService, InputBegan

1 answer

✓ Accepted answer
 --  This should make the animation work. Should be a local script in starterGui.
-- Don't delete your scripts. Just disable them and make sure this plays the animation

Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
cool = true

mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key == "z" then
		if cool == true then
			cool = false
			local Anim = Instance.new("Animation")
			Anim.AnimationId = "rbxassetid://000"
			local humanoid = plr.Character:WaitForChild("Humanoid")
			local playanim = humanoid:LoadAnimation(Anim)
			playanim:Play()
		end
	end
end)

1 comment

0

keydown is decaperated

This discussion is preserved as it was. New answers, comments, and votes are closed.