Player stops when equipping specific tool?

So the player stops when equipping the bat but the other items don’t make th player stop. only happens when I’m running.

Bat code:

wait(0.1)
local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local char = plr.Character
local Idle = char.Humanoid:LoadAnimation(script.Animations.Idle)
local Equip = char.Humanoid:LoadAnimation(script.Animations.Equip)
local equipped = false
local attacking = false
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Handle)
durability = 12
local attack = char.Humanoid:LoadAnimation(script.Animations.Attack)
local broken = false
Hitbox.OnHit:Connect(function(hit, humanoid)
	if humanoid.Parent ~= char and humanoid.Parent.Transformed.Value == true then
		script.Parent.Handle.Hit:Play()
		local damage = math.random(15,25)
		local Player = Players:GetPlayerFromCharacter(script.Parent.Parent)
		
		local Speed = 25
		local Force = 40000

		local TotalForce = Force

		local KnockBack = Instance.new("BodyVelocity",hit.Parent:FindFirstChild("Torso"))

		KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
		KnockBack.Velocity = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed -- based on the direction YOUR character is facing.
		game.Debris:AddItem(KnockBack,0.1)


		humanoid:TakeDamage(damage)
		if humanoid:FindFirstChild("Scientist") then
			if humanoid.Parent.Main.Hurt.Value == false then
				game.ReplicatedStorage.Remotes.Message.MessageEdit:FireClient(Player,"text","You hit the Scientist, What a Horriable person you are",Color3.new(1, 0.298039, 0.298039))
				humanoid.Parent.Main.Hurt.Value = true
				wait(8)
				game.ReplicatedStorage.Remotes.Message.MessageEdit:FireClient(Player,"text","What. Have. You. Done.",Color3.new(1, 0.298039, 0.298039))
			end
		end
		if durability == 0 then
			Hitbox:HitStop()
			script.Parent.Handle.Transparency = 1
			script.Parent.Handle.Break:Play()
			script.Parent.Handle.ParticleEmitter:Emit(50)
			game.ReplicatedStorage.Remotes.Message.MessageEdit:FireClient(Player,"text","Your bat broke",Color3.new(1, 0.298039, 0.298039))
			broken = true
			Equip:Stop()
			Idle:Stop()
			attack:Stop()
			wait(1)
			script.Parent:Destroy()
		end
		durability = durability - 1
	end
end)

script.Parent.Equipped:Connect(function()
	print("Equiped")
	if not broken then
		print("EquipedNotBroken")
		script.Parent.Handle.Equip:Play()
		equipped = true
		Equip:Play()
		Equip.Stopped:Wait()
		if equipped == false then
			print("Returned")
			return
		end
		print("IdlePlay")
		Idle:Play()
	else
		plr.Character.Humanoid:UnequipTools()
	end
end)


script.Parent.Unequipped:Connect(function()
	print("Unequipped")
	equipped = false
	Idle:Stop()
	Equip:Stop()
end)
script.Parent.Activated:Connect(function()
	print("Activated")
	if not attacking and equipped and durability >= 0 then
		print("NotAttacking")
		
		attack:Play()
		attacking = true
		script.Parent.Handle.Prepare:Play()
		wait(0.35)
		Hitbox:HitStart()
		script.Parent.Handle.Swing:Play()
	
		wait(0.4)
		Hitbox:HitStop() 
		wait(2)
		attacking = false
		wait(0.4)

	end
end)

Running code:

local Player = game.Players.LocalPlayer;
local Parent = script.Parent;
local Humanoid = Parent:WaitForChild("Humanoid");

local TweenService = game:GetService("TweenService");

local Sprint = Humanoid:LoadAnimation(script:WaitForChild("Sprint"))
local Sprinting = false

local connection

game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProccesed)
	if (Input.KeyCode == Enum.KeyCode.LeftShift) and Parent:FindFirstChild("Humanoid") and Humanoid.Health > 0 and Humanoid.WalkSpeed ~= 0 and not gameProccesed and script.SprintLock.Value == false then
		TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {
			FieldOfView = 80
		}):Play();
		Humanoid.WalkSpeed = 23
		local signal = Humanoid:GetPropertyChangedSignal("MoveDirection")
		connection = signal:Connect(function()
			if Humanoid.MoveDirection.Magnitude > 0 and Humanoid.WalkSpeed == 23 then
				if not Sprint.IsPlaying then
					Sprint:Play(.2)
				else
					return
				end
			elseif Humanoid.MoveDirection.Magnitude <= 0 then
				Sprint:Stop(.25)
			end
		end)
		Sprinting = true;
	end;
end);

game:GetService("UserInputService").InputEnded:Connect(function(Input)
	if (Input.KeyCode == Enum.KeyCode.LeftShift) and Parent:FindFirstChild("Humanoid") and Humanoid.Health > 0 and Humanoid.WalkSpeed ~= 0 then
		TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {
			FieldOfView = 70
		}):Play();
		connection:Disconnect()
		Humanoid.WalkSpeed = 16
		Sprint:Stop(.25)
		Sprinting = false;
	end;
end);

game:GetService("RunService").Heartbeat:Connect(function()
	if Humanoid.MoveDirection.Magnitude == 0 then
		Sprint:Stop()
		Sprinting = false
	end
	
	if Humanoid.MoveDirection.Magnitude > 0  and Humanoid.WalkSpeed == 23 then
		Sprinting = true
	end
	
	script.SprintLock.Changed:Connect(function()
		if script.SprintLock.Value == true then
			Sprint:Stop(.25)
			Sprinting = false
		elseif script.SprintLock.Value == false then
			return
		end
	end)
end)

--[[
game:GetService("RunService").Heartbeat:Connect(function()
	if Humanoid.WalkSpeed > 0 and not Humanoid.Sit then
		if Sprinting == true then
			Sprint:Play()
		else
			Sprint:Stop()
		end
	end
end);
]]

did u check the “Bat” is anchored or not

If it were anchored he would teleport to the place where the bat would be placed in the workspace

When you are in testing and holding the bat, check your characterwalkspeed.

2 Likes

Strange I just deleted the tool and pasted the components in a new one and it worked but heres the solution anywaysince the speed helped me find it