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 4 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 4 years ago
Edited 4 years ago

You need to use UserInputService

you will need to use events of it:

> input began

> input ended

01local UIS = game:GetService("UserInputService")
02local Players = game:GetService("Players")
03 
04local Client = Players.LocalPlayer
05 
06local Animation = Instance.new("Animation")
07Animation.AnimationId = "rbxassetid://6317159485"
08Animation.Parent = Client.Character
09Animation.Looped = true
10 
11local Current = nil
12 
13UIS.InputBegan:Connect(function(Self, GPE)
14   if Self.KeyCode == Enum.KeyCode.E and not GPE then
15      Current = Client.Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
View all 24 lines...

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 — 4y
Ad

Answer this question