Walking animation playing while my other animation is playing

Hey, i have tried to making a little button system, where if u click it, it plays a cutscene, with a cool button pressing animation. But if i press the button while walking, it still keeps on doing the walk animation:
image
(this is in the middle of the cutscene)

this is the server script

local players = game:GetService("Players")
local clickdetector = script.Parent.ClickDetector
local anim = script.Parent.TutAnim1

local animtime = 151/60 + 1 -- 151 frames / 60 fps = 2.52 seconds + 1(just a bit of extra time)



local event = game:GetService("ReplicatedStorage").TutEvent1

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
		local humanoid = char:FindFirstChild("Humanoid")
		
		local animator = humanoid:FindFirstChild("Animator")
		local loadedanim = animator:LoadAnimation(anim)
		
		clickdetector.MouseClick:Connect(function()
			clickdetector.MaxActivationDistance = 0
			event:FireClient(plr,animtime)
			
			HumanoidRootPart.CFrame = CFrame.new(16.3, 3, -4.5)
			HumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(-90), 0)
			HumanoidRootPart.Anchored = true
			
			plr.CameraMode = Enum.CameraMode.Classic
			
			loadedanim:Play()
			
			wait(animtime*2)-- Times 2 is for backing out of the anim
			
			HumanoidRootPart.Anchored = false
			clickdetector.MaxActivationDistance = 3
			plr.CameraMode = Enum.CameraMode.LockFirstPerson
		end)
	end)
end)

and this is the LocalScript

local TweenService = game:GetService("TweenService")

local event = game:GetService("ReplicatedStorage").TutEvent1



event.OnClientEvent:Connect(function(animtime)
	local camera = game:GetService("Workspace").Camera


	local tweenInfo = TweenInfo.new(
		animtime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		true,
		0
	)

	local tween

	function tween(tutcam1, tutcam2)
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = tutcam1.CFrame
	
		local tween = TweenService:Create(camera,tweenInfo, {CFrame = tutcam2.CFrame})
		tween:Play()
	
		task.wait(animtime)
	
		camera.CameraType = Enum.CameraType.Custom
	end
	wait(0.5)
	tween(game.Workspace.Cameras.TutCam1,game.Workspace.Cameras.TutCam2)
end)
1 Like
local players = game:GetService("Players")
local clickdetector = script.Parent.ClickDetector
local anim = script.Parent.TutAnim1

local animtime = 151/60 + 1 -- 151 frames / 60 fps = 2.52 seconds + 1(just a bit of extra time)

local event = game:GetService("ReplicatedStorage").TutEvent1

players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        
        local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
        local humanoid = char:FindFirstChild("Humanoid")
        
        local animator = humanoid:FindFirstChild("Animator")
        local loadedanim = animator:LoadAnimation(anim)
        
        clickdetector.MouseClick:Connect(function()
            clickdetector.MaxActivationDistance = 0
            event:FireClient(plr, animtime)
            
            -- Store the original WalkSpeed
            local originalWalkSpeed = humanoid.WalkSpeed
            humanoid.WalkSpeed = 0 -- Disable walking
            
            HumanoidRootPart.CFrame = CFrame.new(16.3, 3, -4.5)
            HumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(-90), 0)
            HumanoidRootPart.Anchored = true
            
            plr.CameraMode = Enum.CameraMode.Classic
            
            loadedanim:Play()
            
            wait(animtime * 2) -- Times 2 is for backing out of the anim
            
            HumanoidRootPart.Anchored = false
            humanoid.WalkSpeed = originalWalkSpeed -- Restore walking speed
            clickdetector.MaxActivationDistance = 3
            plr.CameraMode = Enum.CameraMode.LockFirstPerson
        end)
    end)
end)
1 Like