How can I stop all user input while a function is running?

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)

I don’t know if this reply will be much help, as I am not very educated in the User Input Service.

Last I checked, there was a function inside of UIS that would allow you to stop all input and then resume later after running a different function. I’ll see if I can find it and reply again. But in the mean time you should also see if you can see it.

1 Like

I found something but it didn’t work.

I also found this:

Tool.Activated:Connect(function()

slashTrack:Play()
game.Players.PlayerAdded:Connect(function(plr)
disableEvent:FireClient(plr)

    end) -- server side 

local disableEvent = script.Parent:WaitForChild(“Disable”)
local controls = require(game:GetService(“Players”).LocalPlayer.PlayerScripts.PlayerModule):GetControls()

disableEvent.OnClientEvent:Connect(function()

controls:Disable()

end) – local script

I don’t know if there’s something wrong in the script, the slashTrack animation plays but the player’s movement is still detected by the server. I just need a way to make it so the player’s wasd keys are disabled.

1 Like

I found out how to do it!

Right before the slashTrack:Play(), I made a remote event that looks like this:

local player = game:GetService(“Players”):GetPlayerFromCharacter(Tool.Parent)

		disableEvent:FireClient(player)

This fires a remote event to the client, and inside the local script you should find:

local player = game.Players.LocalPlayer
local disabledEvent = script.Parent:WaitForChild(“Disable”)
local enabledEvent = script.Parent:WaitForChild(“Enable”)
local ContextActionService = game:GetService(“ContextActionService”)
local FREEZE_ACTION = “freezeMovement”

disabledEvent.OnClientEvent:Connect(function()
ContextActionService:BindAction(
FREEZE_ACTION,
function()
return Enum.ContextActionResult.Sink
end,
false,
unpack(Enum.PlayerActions:GetEnumItems())
)
end)

To unfreeze the player you can just do:

ContextActionService:UnbindAction(FREEZE_ACTION)

Hope that helps you!