I’m trying to make my fighter jet shoot bullets that will show to every player but when I send a remote event to the server, it doesn’t work.
Shoot Client:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Bullet = ReplicatedStorage:WaitForChild("Bullet")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local model = script.Parent
local VehicleSeat = model:WaitForChild("VehicleSeat")
local GunPart = model:WaitForChild("GunPart")
local cooldown = 0.1
local currentTime = cooldown
local connection
local function StopFiring()
if connection then
connection:Disconnect()
connection = nil
end
end
local function FireGun()
StopFiring()
connection = RunService.Heartbeat:Connect(function()
if VehicleSeat.Occupant then
local result = game.Players:GetPlayerFromCharacter(VehicleSeat.Occupant.Parent)
if result and tick() - currentTime >= cooldown then
currentTime = tick()
script.ShootGun:FireServer()
elseif not result then
StopFiring()
end
else
StopFiring()
end
end)
end
mouse.Button1Down:Connect(function()
if VehicleSeat.Occupant then
local result = game.Players:GetPlayerFromCharacter(VehicleSeat.Occupant.Parent)
if result then
FireGun()
end
end
end)
mouse.Button1Up:Connect(function()
if VehicleSeat.Occupant then
local result = game.Players:GetPlayerFromCharacter(VehicleSeat.Occupant.Parent)
if result then
StopFiring()
end
end
end)
--------------------------------------------------------------------------------------------------------------------------------------
local launchPower = 8000
local function ShootGun()
local newBullet = Bullet:Clone()
newBullet.CFrame = GunPart.CFrame
newBullet.Parent = workspace
newBullet:ApplyImpulse(newBullet.CFrame.LookVector * launchPower)
game:GetService("Debris"):AddItem(newBullet, 8)
end
script:WaitForChild("ShootGun").OnClientEvent:Connect(function()
ShootGun()
end)
Server:
script.Parent.ShootGun.OnServerEvent:Connect(function(player)
script.Parent.ShootGun:FireAllClients()
end)
Bullet Client:
local part = script.Parent
part.Touched:Connect(function(hit)
local speed = (part.AssemblyLinearVelocity - hit.AssemblyLinearVelocity).Magnitude
if speed >= 100 then
script.BreakPart:FireServer(hit) -- doesn't fire
end
end)
Break Part Server:
local function BreakOthers(part)
for i,v in ipairs(part:GetChildren()) do
if v:IsA("Attachment") then
v:Destroy()
end
end
end
script.Parent.BreakPart.OnServerEvent:Connect(function(player, part)
print("test") ---- nothing
if part then
part:BreakJoints()
BreakOthers(part)
end
end)