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

HELP HELP URGENT CAN SOMEONE HELP ME?

I NEED THIS DONE BY TOMMOROW BUT I DON'T KNOW HOW TO DO IT

wait(2)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Anim = script.Animation

Mouse.KeyDown:connect(function(key)
if key == "e" then
s = player.Character.Humanoid:LoadAnimation(Anim)
s:Play()
end
end)

HELP WOULD REALLY BE APPRECIATED

1 comment

0

Thanks man

1 answer

So your animation code works fine, but it seems to be that you are using Mouse.KeyDown [deprecated] instead of a newer function. Let me help you on this code.

--EDIT: Defined variables
wait(2)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Anim = script.Animation

--First we create the function for the key press
function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		s = player.Character.Humanoid:LoadAnimation(Anim)
		s:Play()
	end
end
 
--Then we bind it.
game.ContextActionService:BindAction("keyPress", onKeyPress, false, "e")

What this basically does is that it makes use of ContextActionService which is a useful service for a lot of things, and binds a keypress action checking for the key "e" which is the key you demonstrated above, then it runs the animation code. Remember to put this in a localscript, and lua on!

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