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

How to make player unable to move during animation?

Asked by 5 years ago
local function Activated()
 if Toggled == false then
   Toggled = true
  local animTrack1 = Humanoid:LoadAnimation(Animation1)
   animTrack1:Play()
  wait(1.45)
  local animTrack2 = Humanoid:LoadAnimation(Animation2)
   animTrack2:Play()
  wait(29.95)
 else
  Toggled = false
  local animTrack3 = Humanoid:LoadAnimation(Animation3)
   animTrack3:Play()
  wait(1.25)
  local ActiveTracks = Humanoid:GetPlayingAnimationTracks()
  for _,v in pairs(ActiveTracks) do
    if v.Name == Animation1 or Animation2 
     then 
      v:Stop()
     end
  end
 end
end

Button.Activated:Connect(Activated)

This script was meant to make the character play an animation after the player presses the GUI button, but the player is still able to move while the animation is playing, is there some way i can make the player unable to move during the animations?

And if you can please give me a feedback of my script, any help is appreciated.

1 answer

Log in to vote
0
Answered by
asgm 109
5 years ago

Hello! I learned this very recently and it should help you. If you're using Roblox animation editor, you can add event marker by right clicking the black-ish bar above the keyframes. You can declare the event at the beginning and at the end of your animation, with your preferred argument (say, WalkSpeed). To connect the function you declared, you use: AnimationTrack:GetMarkerReachedSignal("functionName"):Connect(function(argument) end)

Here is my example.

loadedWalk:GetMarkerReachedSignal("stepsound"):Connect(function(sound)
    local sound = 10 -- this is volume
    FootstepSound.Volume = sound
    FootstepSound:Play()
end)

For your situation, you can do

animTrack:GMRS("blabla"):Cnct(fnct(arg)
if humanoid.WalkSpeed = (originalWalkspeed) then
    humanoid.WalkSpeed = 0
if humanoid.WalkSpeed = 0 then
    humanoid.WalkSpeed = (originalWalkspeed)
end)

since your event triggers twice, I used if .. then to check if your humanoid can walk or has been stopped. Hope this helped :)

0
Edit : I didn't really look at your code cuz I'm lazy to do so. Sorry if this doesn't help! asgm 109 — 5y
0
It worked perfectly!Thank you so much! kevinsoaresv 47 — 5y
Ad

Answer this question