I have a plane that shoots bullets but when I shoot while flying, the bullet would sometimes go inside the plane. I set the bullet network to the player and the plane network to the player too.
Shoot Gun: (server)
local ServerStorage = game:GetService("ServerStorage")
local Bullet = ServerStorage:WaitForChild("Bullet")
local model = script.Parent.Parent
local GunPart = model:WaitForChild("GunPart")
local function SetNetworkOwner(part, owner)
local result = part:CanSetNetworkOwnership()
if result then
part:SetNetworkOwner(owner)
end
end
local function ShootGun(player)
local newBullet = Bullet:Clone()
newBullet.CFrame = GunPart.CFrame
newBullet.Parent = workspace
SetNetworkOwner(newBullet, player)
end
script.Parent.ShootGun.OnServerEvent:Connect(function(player)
ShootGun(player)
end)
Script inside bullet: (client)
local part = script.Parent
local launchPower = 1000
part.Touched:Connect(function(hit)
local speed = (part.AssemblyLinearVelocity - hit.AssemblyLinearVelocity).Magnitude
if speed >= 250 then
script.BreakWeld:FireServer(hit)
end
end)
part.AssemblyLinearVelocity = part.CFrame.LookVector * (launchPower + part.AssemblyLinearVelocity.Magnitude)
How can I fix this?