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

FireAllClients() fire's every players gun? (HELP)

So I am making a gun using raycast, I am making a client side bullet and a server hit detection but there's one problem whenever I fire my gun, the other clients also fire their bullet without even pressing their mouse. Can anyone help me? So here's my script:

Bullet.OnServerEvent:Connect(function(player, mospos, startofbul)
	local origin = startofbul.Position
	local direction = ( mospos -origin).Unit
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {script.Parent, script.Parent.Parent}
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.IgnoreWater = true
	
	local result = workspace:Raycast(origin, direction*200, params)
	if result then
		local hum = result.Instance.Parent:FindFirstChild("Humanoid")
		if hum then
			hum:TakeDamage(30)
		end
	end
	
	
	
	for i,v in pairs(game:GetService("Players"):GetPlayers()) do
			bullet:FireClient(v) -- This is the problem
		end
	
end)

I want it to be only seen by other clients, not make them fire their gun. Can anyone please give me an idea?

1 comment

0

The problem is most likely on the receiving end of that remote event. What you should be doing (and hopefully are) is passing the gun alongside the :FireAllClients() so the client knows which gun to show the effects for.

1 answer

It fires every players gun because FireAllClients fires all the client You are litterally

 for i,v in pairs(game:GetService("Players"):GetPlayers()) do
           bullet:FireClient(v) -- This is the problem
end

This fires every single player

you do a pair loop to get every single players by doing :GetPlayers() and you fire the client on every single client

4 comments

0

Then how do i make it only fire on 1 client and only seen by other clients?

0

You use :FireClient() and pass in the player who you want to fire it to in the brackets.

0

How canthe other clients see the bullet

0

What do I need to do to make the other players see the bullet, because if on the server it will cause bullet lag problems? 1

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