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

Shooting a block with bodyVelocity?

Asked by
Kryddan 261 Moderation Voter
9 years ago

I try to do so whenever i press the "Y" button i should shoot away a block from myself into the direction where my mouse is. It works until i move, if i move and then press "Y" the block spawns but never shoots away it just sits still.

here is my code and i hope you can help me.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    key:lower()
    if key == "y"  then
        local x = Instance.new("Part", workspace)
        x.Size = Vector3.new(5,5,5)
        x.Name = "FlyingBrick"
        x.BrickColor = BrickColor.Random()
        x.TopSurface = "Smooth"
        x.BottomSurface = "Smooth"
        x.Material = "Concrete"
        x.CFrame = player.Character.Torso.CFrame + Vector3.new(0,1,0)       
        x.Anchored = false
        x.CanCollide = false
        local xvelocity = Instance.new("BodyVelocity", x)
        xvelocity.maxForce = Vector3.new(math.huge,math.huge,math.huge)
        xvelocity.P = 1250
        xvelocity.velocity = mouse.Hit.lookVector * 50
    end
end)

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago

xvelocity.velocity = CFrame.new(player.Character.Torso.Position, mouse.Hit.p).lookVector * 50

replace line 20 with this

0
Thx for the answer but it still won't work! Kryddan 261 — 9y
0
never mind i just removed line 19 xvelocity.P = 1250 and it worked! Kryddan 261 — 9y
Ad

Answer this question