Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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 ^

0
if char.Torso:findFirstChild("BodyVelocity") then Discern 1007 — 8y

1 answer

Log in to vote
0
Answered by
neoG457 315 Moderation Voter
8 years ago
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.

0
Thanks! :) zipper01 62 — 8y
Ad

Answer this question