Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If Statement Error: BodyVelocity is not a valid member of Part?

I'm making a double jump script but I'm getting an annoying error. I have no clue why but it's not skipping the first command.

plr = script.Parent.Parent
char = plr.Character
mouse = plr:GetMouse()



	function onKeyDown(key)
	
		key = key:lower()
	

		
		if key:byte() == 32 then --spacebar is 32
			if char.Torso.BodyVelocity then -- This is line 44
			print("BodyVelocity is already in use")
			else
			local bv = Instance.new("BodyVelocity", plr.Character.Torso)
			bv.maxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.velocity = Vector3.new(0,40,0)
			wait(.25)
			bv:Destroy()
		end
		end
	end -- func onKeyDown

mouse.KeyDown:connect(onKeyDown)

After I'd run this script I'd get an error saying

16:59:32.699 - BodyVelocity is not a valid member of Part 16:59:32.700 - Script 'Players.Player.Backpack.onkeydown', Line 44 16:59:32.700 - Stack End

I've marked line 44 in the script ^

1 comment

0

if char.Torso:findFirstChild("BodyVelocity") then

1 answer

✓ Accepted answer
plr = script.Parent.Parent
char = plr.Character
mouse = plr:GetMouse()



    function onKeyDown(key)

        key = key:lower()



        if key:byte() == 32 then --spacebar is 32
            if char.Torso:findFirstChild("BodyVelocity") then -- This is line 44
            print("BodyVelocity is already in use")
            else
            local bv = Instance.new("BodyVelocity", plr.Character.Torso)
            bv.maxForce = Vector3.new(math.huge, math.huge, math.huge)
            bv.velocity = Vector3.new(0,40,0)
            wait(.25)
            bv:Destroy()
        end
        end
    end -- func onKeyDown

mouse.KeyDown:connect(onKeyDown)

You have to use :findFirstChild("") to find BodyVelocity in the Torso.

1 comment

0

Thanks! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.