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

What's wrong with this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

The ball is created, and it stays in front of me. It doesn't move forward like it should. It decides to stop working after about 2 shots. Sometimes one.

Player = game.Players.LocalPlayer
Char = Player.Character
Torso = Char.Torso
Mouse = Player:GetMouse()
Attack = false
function onKeyDown(key)
    key = key:lower()
    if key == "f" and Attack ==  false then
        Attack = true
        local Ball = Instance.new("Part")
        Ball.Parent = workspace
        Ball.Shape = "Ball"
        Ball.Size = Vector3.new(5,5,5)
        Ball.BrickColor = BrickColor.new("Really red")
        Ball.Transparency = 0.4
        Ball.TopSurface = 0
        Ball.BottomSurface = 0
        Ball.CFrame = Torso.CFrame * CFrame.new(0,0.5,-4)
        local Bv = Instance.new("BodyVelocity")
        Bv.Parent = Ball
        Bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
        Bv.P = 1250 
        Bv.velocity = Torso.CFrame.lookVector * 1000
        game.Debris:AddItem(Ball,4)
        wait(3)
        Attack = false
    end
end
Mouse.KeyDown:connect(onKeyDown)

1 answer

Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

Since you parented the part to the Workspace before you added the BodyVelocity, it isn't being picked up by the physics engine. Move Ball.Parent = workspace from line 11 to line 24 and it works.

0
Why is that the case? It shouldn't matter at what point the BodyVelocity enters the part BlueTaslem 18071 — 10y
0
I don't know why it is the case. Merely 2122 — 10y
Ad

Answer this question