I put this local script in StarterCharacterScripts:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Animate = 0 local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Animate = 0 local Humanoid = player.Character:FindFirstChild('Humanoid')
mouse.KeyDown:Connect(function(Key)
if Key == "e" then
local Animation = Instance.new("Animation", player.Character)
Animation.AnimationId = "rbxassetid://6317159485"
Animate = Humanoid:LoadAnimation(Animation)
Animate:Play()
end
end)
mouse.KeyUp:Connect(function(Key) if Key == "e" then Animate:Stop() end end)
It's meant to carry out the animation when holding e, but nothing happens. Do you know how to help?
You need to use UserInputService
you will need to use events of it:
> input began
> input ended
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local Players = game:GetService( "Players" ) |
03 |
04 | local Client = Players.LocalPlayer |
05 |
06 | local Animation = Instance.new( "Animation" ) |
07 | Animation.AnimationId = "rbxassetid://6317159485" |
08 | Animation.Parent = Client.Character |
09 | Animation.Looped = true |
10 |
11 | local Current = nil |
12 |
13 | UIS.InputBegan:Connect( function (Self, GPE) |
14 | if Self.KeyCode = = Enum.KeyCode.E and not GPE then |
15 | Current = Client.Character:WaitForChild( "Humanoid" ):LoadAnimation(Animation) |
Tell me if this works, also:
:GetMouse() is incredibly deprecated, I don't recommend using it and .KeyDown
detects a key when it's pushed and not when held.