Shooting a block with bodyVelocity?
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.
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
04 | mouse.KeyDown:connect( function (key) |
07 | local x = Instance.new( "Part" , workspace) |
08 | x.Size = Vector 3. new( 5 , 5 , 5 ) |
09 | x.Name = "FlyingBrick" |
10 | x.BrickColor = BrickColor.Random() |
11 | x.TopSurface = "Smooth" |
12 | x.BottomSurface = "Smooth" |
13 | x.Material = "Concrete" |
14 | x.CFrame = player.Character.Torso.CFrame + Vector 3. new( 0 , 1 , 0 ) |
17 | local xvelocity = Instance.new( "BodyVelocity" , x) |
18 | xvelocity.maxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
20 | xvelocity.velocity = mouse.Hit.lookVector * 50 |