basically I want to make the bullet shoot in the right direction with the orientation going the right way to and not side ways no matter where I’m looking, I am not exactly sure what to do with this.
Here is the codes I have,
LocalScript (located in gun tool) :
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
script.Parent.Shot:FireServer(mouse,mouse.Target)
end)
Script (located in gun tool) :
local FirePart = script.Parent.FirePart
local speed = 100
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
function CreateBullet(mouse, target)
local Bullet = game.ReplicatedStorage:WaitForChild("Bullet"):Clone()
Bullet.Parent = workspace
Bullet.CFrame = FirePart.CFrame
Bullet.Velocity = CFrame.new(FirePart.Position, target.Position).lookVector * 100
end
script.Parent.Shot.OnServerEvent:Connect(function(plr,mouse, target)
CreateBullet(mouse, target)
if not target:IsDescendantOf(plr.Character) then
if target.Parent:FindFirstChild("Humanoid") then
if target.Name == "Head" then
target.Parent.Humanoid.Health -= 20
else
target.Parent.Humanoid.Health -= 10
end
end
end
end)
Change The FirePart CFrame, You’re Using The CFrame Of It For The Bullet CFrame, And If You Want To (Optional): You Can Use FastCast Module To Make The Bullet Speed Constant, You Can Make The Bullet Size Smaller So Its More Realistic And Also You Can Add A Trail So It Look Nice, If You Dont Know How To Use Fastcast You Can See This Tutorial