Hello! I’ve been trying to pause an animation when a player is holding the “E” key. The code works properly on the first time, but then it started to get some errors.
The problem is, when I’m only pressing it once, it will still pause the animation. How do I make it that the animation will only stop whenever im holding a key, and it will play again whenever I release the key?
Here’s the code :
– local script
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local fireEvent = RS:WaitForChild("Fire")
local endEvent = RS:WaitForChild("End")
UIS.InputBegan:Connect(function(input, typing)
if input.KeyCode == Enum.KeyCode.E and typing == false then
fireEvent:FireServer()
end
end)
UIS.InputChanged:Connect(function(input, GPE)
UIS.InputEnded:Connect(function(input, typing)
if input.KeyCode == Enum.KeyCode.E and typing == false then
endEvent:FireServer()
end
end)
end)
– Server script
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local RS = game:GetService("ReplicatedStorage")
local fireEvent2 = RS:WaitForChild("Fire")
local endEvent2 = RS:WaitForChild("End")
local db = false
fireEvent2.OnServerEvent:Connect(function(player)
if db == false then
db = true
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://9168220359"
local hikenPart = script.HikenFlame:Clone()
local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
animationTrack:Play()
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpHeight = 0
character.Humanoid.AutoRotate = false
animationTrack:GetMarkerReachedSignal("Charge"):Connect(function(paramString)
local fire = script.HandFlame.Attachment:Clone()
fire.Parent = player.Character.RightHand
animationTrack:AdjustSpeed(0)
endEvent2.OnServerEvent:Connect(function(player)
animationTrack:AdjustSpeed(1)
fire:Destroy()
end)
animationTrack:GetMarkerReachedSignal("fireHiken"):Connect(function(paramString)
local startPos = character.RightHand.Position
local endPos = character.HumanoidRootPart.Position + character.HumanoidRootPart.CFrame.LookVector * 100
local antiGravity = .5
local bf = Instance.new("BodyForce")
bf.Force = Vector3.new(0, hikenPart:GetMass() * 196, 0)
bf.Parent = hikenPart
hikenPart.CFrame = CFrame.new(startPos, endPos)
hikenPart.Parent = workspace
hikenPart.Velocity = hikenPart.CFrame.LookVector * 70
hikenPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= character.Name then
local humanoid = hit.Parent.Humanoid
humanoid.Health -= 10
end
end)
animationTrack.Stopped:Wait()
hikenPart:Destroy()
character.Humanoid.WalkSpeed = 16
character.Humanoid.JumpHeight = 7.5
character.Humanoid.AutoRotate = true
db = false
end)
end)
end
end)
end)
end)
Any Help is appreciated ! Thanks !