Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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.

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

✓ Accepted answer

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

replace line 20 with this

2 comments

0

Thx for the answer but it still won't work!

0

never mind i just removed line 19 xvelocity.P = 1250 and it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.