Help with flying move

In my game I have some tools that allow you to fly by pressing “B”. It works just fine when people use the ability sometimes. But sometimes whenever a player dies it just will stop working. It is not just when they die, sometimes it still works after death. It just basically walks normally and has the animation but doesn’t fly. I looked up the issue and couldn’t find anything that worked, and it’s hard for me to find out how to fix it when I don’t really know what is causing it. So if someone can tell me if there is something wrong with this script that would be great.

Here is the script of flying

elseif Input.KeyCode == Enum.KeyCode.B and enabled == false and Tool.Equip.Value == true then
			if toggle == false and Debounce == true then
				toggle = true
				Debounce = false
				remote:FireServer("Flying") -- we fireserver our remoteevent so the server creates the move
				local BV = Instance.new("BodyVelocity",Torso)
				BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				while toggle == true and Tool.Equip.Value == true do
					wait()
					plr.Character.HumanoidRootPart.CFrame = CFrame.new(plr.Character.HumanoidRootPart.Position, Vector3.new(Mouse.Hit.p.x,plr.Character.HumanoidRootPart.Position.y,Mouse.Hit.p.z))
					BV.Velocity = Mouse.Hit.lookVector * 50
				end
			end
			if toggle == true and Debounce == false then
				toggle = false
				remote:FireServer("Flying") -- we fireserver our remoteevent so the server creates the move
				Torso:FindFirstChildOfClass("BodyVelocity"):Destroy()
				wait(1)
				Debounce = true
				enabled = false
			end
		end

put the localscript in StarterCharacterScripts And check if the player’s health is Above 0 in the localscript and in the ServerScript.

1 Like