Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make the bullets fired from my gun visible to all players and not just the shooter?

I am rebuilding my gun script to work with filtering enabled. The gun works but only the shoot can see the bullets. I am not sure if the sound can be heard by the other players.

I know that I need to use a remote event. I just don't know how to let the game know who created the bullet, where the gun was aimed, where the bullets origin should be, and what direction the bullet should fly. The current origin is gun.Main.

Thanks a lot for your help. I really do need it.

--player variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

--gun variables
local gun = script.Parent 


if not game.workspace:FindFirstChild("Bullet") then
	local bullet_storage = Instance.new("Folder", workspace)
	bullet_storage.Name = "Bullet"
else
	--nothing
end

function getBullet()
	gun.Handle.Fire:Play()--error
	local mh = mouse.Hit
	local B = Instance.new("Part", workspace.Bullet)
	game:GetService("Debris"):AddItem(B, 8)
	B.CFrame = gun.Main.CFrame + (player.Character.Torso.CFrame.lookVector * 2)
	B.CFrame = CFrame.new(B.Position, mh.p)
	B.FormFactor = "Custom"
	B.Size = Vector3.new(0.2, 0.2, 0.2)
	B.BrickColor = BrickColor.Black()
	B.CanCollide = true
	local velo = Instance.new("BodyVelocity", B)
	velo.velocity = B.CFrame.lookVector * 120
	velo.maxForce = Vector3.new(math.huge, math.huge, math.huge)
	B.Touched:connect(function(hit)
		local toRespawn = game.Players:GetPlayerFromCharacter(hit.Parent)
		local event = game.ReplicatedStorage:WaitForChild("FireGun"):FireServer(toRespawn)
	end)

end

mouse.Button1Down:connect(function()
	getBullet()
end)

1 answer

✓ Accepted answer

As I told you here, you need to write a RemoteEvent. This time, have the event fire when you want to shoot. Then, on the server, recieve the event and shoot the bullet.

So, it'll look a bit like this:

--server code
local event = game.ReplicatedStorage.RemoteEvent --replace with wherever the RemoteEvent is
event.onServerEvent:connect(function(player)
    -- shoot bullet
end)
--client code
local event = game.ReplicatedStorage.RemoteEvent --replace with wherever the RemoteEvent is
--do the below then you want to fire
event:FireServer()

This discussion is preserved as it was. New answers, comments, and votes are closed.