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?
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