So I was trying to make a block system where if u hold f it holds block then letting go of the f key resumes that animation, everything seems to be working fine but it doesn’t register that I paused the animation.
1 Like
Ello!
Does this work?
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local anim = Instance.new("Animation")
anim.Parent = player
anim.AnimationId = "rbxassetid://119978299598900"
local character = player.Character
local hum = character:FindFirstChild("Humanoid")
local track = hum:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Idle
local blockKey = "f"
local isBlocking = false -- To keep track of whether we're blocking
local pauseTime = 0 -- To store animation position when paused
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode[blockKey:upper()] and not isBlocking then
isBlocking = true
print("Blocking works")
track:Play()
track:GetMarkerReachedSignal("BlockEvent"):Connect(function()
track:AdjustSpeed(0) -- Optional: This can freeze the animation if you need it
print("does this even work")
end)
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode[blockKey:upper()] and isBlocking then
isBlocking = false
pauseTime = track.TimePosition -- Store current position
track:Stop() -- Stop the animation (simulate pause)
print("Animation paused at", pauseTime)
end
end)
mouse.KeyDown:Connect(function(key) -- For legacy input handling, if required
if key == blockKey then
if isBlocking then
isBlocking = false
pauseTime = track.TimePosition
track:Stop()
else
isBlocking = true
track.TimePosition = pauseTime -- Resume from paused position
track:Play()
end
end
end)
I added an isBlocking
boolean to track the block state and I also switched to UserInputService
for InputBegan
and InputEnded
i used your script that animation works fine but it still doesn’t stop, could it be an issue with my actual animation?
1 Like