Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
R_oven 2
6 years ago
Edited 6 years ago

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)

0
Please format your code correctly. https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site iDarkGames 483 — 6y

1 answer

Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago

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

Answer this question