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 ^
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.