Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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?

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. radiant_Light203 1166 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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

0
Then how do i make it only fire on 1 client and only seen by other clients? RichDiggerW189 2 — 2y
0
You use :FireClient() and pass in the player who you want to fire it to in the brackets. Soban06 410 — 2y
0
How canthe other clients see the bullet RichDiggerW189 2 — 2y
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 RichDiggerW189 2 — 2y
Ad

Answer this question