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

Player won't carry out animation?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
OK, I'll see if that works, thanks! Valkyrie1277 28 — 3y
Ad

Answer this question