Hello!
I made my first gun recently that fires bullets from a tool. There is a delay in the shot and it’s not super accurate so I was wondering if there is a better way to shoot bullets. Here are my scripts:
Here’s a LocalScript inside of the Tool Handle:
local gun = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = game.ReplicatedStorage:WaitForChild("TennisBall")
gun.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
RemoteEvent:FireServer(gun.Position, mouse.Hit.p)
end)
end)
And here’s a script in ServerScriptService:
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = game.ReplicatedStorage:WaitForChild(“BulletCreator”)
RemoteEvent.OnServerEvent:Connect(function(player,gunPos,mousePos)
local Bullet = Instance.new("Part")
Bullet.Name = "Bullet"
Bullet.Parent = game.Workspace
Bullet.Shape = Enum.PartType.Ball
Bullet.Size = Vector3.new(1.5, 1.5, 1.5)
local distance = (mousePos - gunPos).magnitude
local speed = 500
Bullet.CFrame = CFrame.new(gunPos,mousePos)
Bullet.Velocity = Bullet.CFrame.lookVector * speed
wait(3)
Bullet:Destroy()
end)
Any suggestions are appreciated. Thanks!