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

Player won't carry out animation?

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?

1 answer

✓ Accepted answer

You need to use UserInputService

you will need to use events of it:

> input began

> input ended

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")

local Client = Players.LocalPlayer

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6317159485"
Animation.Parent = Client.Character
Animation.Looped = true

local Current = nil

UIS.InputBegan:Connect(function(Self, GPE)
   if Self.KeyCode == Enum.KeyCode.E and not GPE then 
      Current = Client.Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
      Current:Play()
   end
end)

UIS.InputEnded:Connect(function(Self, GPE)
   if Self.KeyCode == Enum.KeyCode.E and not GPE then 
      Current:Stop()
   end
end)

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.

1 comment

0

OK, I'll see if that works, thanks!

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