Character wont move when script runs. Please help

I made a local script in a tool where it creates a particle effect and a hit box that deals damage in front of the player. Everything works great. But, for some reason the player can’t move when the flamethrower is activated, (the tool). Here’s the script, its located in a tool in starterpack…

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local canshoot = true


function OnActivation()
	
	if canshoot == true then
		canshoot = false
		--local sound = script.Parent.Thunder
		--sound:Play()
	print('Activation works')
		local ball = Instance.new("ParticleEmitter")
		ball.Texture = 'http://www.roblox.com/asset/?id=290556384'

		ball.Color = ColorSequence.new{
			ColorSequenceKeypoint.new(0, Color3.new(1, 0, 0)),
			ColorSequenceKeypoint.new(0.33, Color3.new(1, 0.666667, 0)),
			ColorSequenceKeypoint.new(0.66, Color3.new(1, 1, 0)),
			ColorSequenceKeypoint.new(1, Color3.new(1, 0.945098, 0.721569))
		}
		ball.Lifetime = NumberRange.new(1,2)
		ball.Rate = 100
		ball.Speed = NumberRange.new(30,30)
		ball.SpreadAngle = Vector2.new(15,15)
		ball.Parent = root.Fire
		local ball2 = Instance.new("Part")
		ball2.Shape = Enum.PartType.Block
		ball2.Size = Vector3.new(6,3.5,13.2)
		ball2.Transparency = 0
		ball2.Massless = true
		ball2.CanCollide = false
		ball2.Parent = workspace
		ball2.Anchored = false


		local newCFrame = root.CFrame *  CFrame.new(Vector3.new(0,0,-7))
	local cf = ball2.CFrame

		ball2.CFrame = newCFrame
		local weld = Instance.new("WeldConstraint")
		weld.Parent = root
		weld.Part0 = root
		weld.Part1 = ball2




	local Velocity = Instance.new("BodyVelocity")

	Velocity.maxForce = Vector3.new(math.huge, math.huge, math.huge) 
		Velocity.Velocity = ball2.CFrame.lookVector * 0 


		Velocity.Parent = ball2
	
	
	ball2.Touched:connect(function(hit) 
		if hit.Parent:FindFirstChild('Humanoid') and hit.Parent ~= player.Character  then
			local humanoid1 = hit.Parent:FindFirstChild('Humanoid')
			humanoid1:TakeDamage(20)
		
	
			end
	end)
	ball2.Touched:connect(function(hit) 
			if hit:IsA("Part")  and hit.Parent ~= player.Character then
				wait(.5)

		
			
		end
		
		end)
		

		wait(10)
		ball2:Destroy()
		ball:Destroy()
		wait(3)
		canshoot = true
	end
	
	end
	
	
tool.Activated:Connect(OnActivation)

Are any of the parts inside the flamethrower anchored/collideable and is the flamethrower welded to your hand?

The flamethrower is supposed to be like a spell, there are no parts in the too except for the script. The flamethrower is welded to the hrp

Any ideas on what could be wrong with the script?

The code you provided won’t stop the character from moving. The problem is probably with the way you made your tool. Did you anchor any parts? Oh I see only when activated.

The character cant move when the tool is activated. the script is parented to the tool. No parts are anchored, the parts are manually made in the script and ancored is set to false.

Saw you edited the post, ye. Any other ideas?

1 Like

Yeah. The problem is probably that the code welds ball2 to the HumanoidRootPart then adds a BodyVelocity with inf max force and velocity set to zero.

BodyVelocities try to make the assembly’s velocity the same as the set velocity. By setting the velocity to zero, it uses inf force to make the character not move.

Problematic lines:

  • Welding ball2 to the HumanoidRootPart
-- Are you sure you want to weld ball2 to the character?
local weld = Instance.new("WeldConstraint")
weld.Parent = root
weld.Part0 = root
weld.Part1 = ball2
  • Setting the BV force to inf and velocity to zero
-- Maybe you wanted to slow the character? If so then use less than math.huge force
Velocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
-- This will always be <0, 0, 0>, maybe you meant like 10 or something, not 0?
Velocity.Velocity = ball2.CFrame.lookVector * 0
1 Like

0 so that the lookvector works. yes weld because the hitbox needs to follow with the player.

I just realised the lookvector isnt needed, maybe thats the issue

IT WAS THE ISSUE IT WORKS!!! Yay… Lookvector was effecting the hitbox which was apart of the character so the character couldnt move because the hitbox couldnt move.

1 Like