I want to make it so while my function is running ( plays an animation ) the game can’t detect player input such as movement.
I don’t want the game to detect movement because I have scripted so when the player detects movement it executes the walking animation and it interrupts the animation mentioned before.
I have tried anchoring the root part of the humanoid, setting the speed to 0, but the game still detects movement so the walking animation executes and it just interrupts my animation.
Any ideas?
This is my script:
–// local Tool = script.Parent
local MyRoot
–Variables
local Event
local state = nil
local idleAnim1
local idleAnim2
players = game:GetService(“Players”)
local slash
disableEvent = Tool.Disable
– Animations
local idle = Tool.Handle.Idle
local walk = Tool.Handle.Walking
Tool.Equipped:Connect(function()
MyRoot = Tool.Parent:FindFirstChild(‘HumanoidRootPart’)
humanoid = Tool.Parent:FindFirstChildWhichIsA(‘Humanoid’)
slash = script.Slash
slashTrack = humanoid:LoadAnimation(slash)
humanoid.WalkSpeed = 10
if humanoid then
idleAnim1 = humanoid:LoadAnimation(idle)
idleAnim1:Play()
--// Check for movement
Event = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
local magnitude = humanoid.MoveDirection.Magnitude
if magnitude <= 0.1 and state ~= "idle" then
state = "idle"
idleAnim1 = humanoid:LoadAnimation(idle)
idleAnim1:Play()
if idleAnim2 then
idleAnim2:Stop()
end
elseif state ~= "other" then
state = "other"
idleAnim2 = humanoid:LoadAnimation(walk)
idleAnim2:Play()
if idleAnim1 then
idleAnim1:Stop()
end
end
end)
else
print('no humanoid')
end
end)
Tool.Unequipped:Connect(function()
Event:Disconnect()
humanoid.WalkSpeed = 16
if idleAnim1 then idleAnim1:Stop() end
if idleAnim2 then idleAnim2:Stop() end
end)
cooldown = false
Tool.Activated:Connect(function()
if cooldown == false then
cooldown = true
local slash = script.Slash
local humanoid = script.Parent.Parent.Humanoid
if idleAnim1 then
idleAnim1:Stop()
end
if idleAnim2 then
idleAnim2:Stop()
end
slashTrack:Play() -- right here the animation gets interrupted if the player presses a,w,s or d.
wait(1)
script.Parent.Clang:Play()
script.Parent.hitpart.Script.Disabled = false
Tool.Parent["Dragon Slayer"].hitpart.CanCollide = true
wait(0.1)
Tool.Parent["Dragon Slayer"].hitpart.CanCollide = false
wait(0.4)
idleAnim1:Play()
wait(1)
script.Parent.hitpart.Script.Disabled = true
wait(4)
cooldown = false
end
end)