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

How do I make it, when I press the key it activate and when I press it again, it deactivate?

I found this animation hotkey from the toolbox. Help, I want to make it when I press the key, activate the animation and when I press it again, it deactivate. Like a switch.

This is the script--

local player = game.Players.LocalPlayer local mouse = player:GetMouse()

function keyD(key) local key = key:lower() local hotkey = script.Hotkey.Value if key == hotkey then

local dance = Instance.new("Animation") dance.AnimationId = "rbxassetid://1506546104" local animloader = player.Character.Humanoid:LoadAnimation(dance) animloader:Play() end end

mouse.KeyDown:connect(keyD)

1 comment

1 answer

This should work :

local player = game.Players.LocalPlayer
local mouse = player:GetMouse
local dance = Instance.new("Animation") 
dance.AnimationId = "rbxassetid://1506546104" 
local animloader = player.Character.Humanoid:LoadAnimation(dance)
local UIS = game:GetService("UserInputService")
debounce = false

UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
local KeyCode = Input.KeyCode
if not gameProcessedEvent then

if KeyCode == Enum.KeyCode.D and debounce == false then
debounce = true
animloader:Play()
wait(3)
debounce = false -- so it can be ran again after 3 seconds
end
end
end)

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