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)
xvelocity.velocity = CFrame.new(player.Character.Torso.Position, mouse.Hit.p).lookVector * 50
replace line 20 with this