So, I am making a gun and want to create a bullet that launches in the direction of gun. I have two problems:
- The Bullet does not move.
- How do I make the bullet move in the direction its facing?
Here is the code for the BodyVelocity:
local event = script.Parent:WaitForChild("Shoot")
local debounce = false
event.OnServerEvent:Connect(function(player, target, gun)
if not debounce then
debounce = true
local bullet = game.ReplicatedStorage.Tools.Bullet:Clone()
bullet.CFrame = gun.Handle.CFrame
local bodyVel = Instance.new("BodyVelocity")
bodyVel.MaxForce = Vector3.new(1000000,1000000,1000000)
bodyVel.Velocity = Vector3.new(0, 10, 0)
bodyVel.P = 2000
bullet.Parent = game.Workspace
bodyVel.Parent = bullet
gun:FindFirstChild("Sound"):Play()
local victim = target.Parent
local victimPlayer = game.Players:GetPlayerFromCharacter(victim)
if victim then
local character = victim
local humanoid = character:FindFirstChild("Humanoid")
--[[if target.Name == "Head" then
humanoid:TakeDamage(50)
else
humanoid:TakeDamage(20)
end]]
end
wait(0.2)
debounce = false
end
end)
Here is a video of the problem:
robloxapp-20210505-1917453.wmv (950.7 KB)