I have a localscript that fires a remote, and a server script that handles shooting the projectile. Now for some reason when trying to shoot a projectile, the server script runs the function once for each player in the game. For example, if there are two players in the game it will fire two projectiles when used.
I’ve tried printing each time something happens, and it shows that the localscript only fires the remote once. However the server script function is run multiple times. I tried including a debounce and this didn’t work, and the number of projectiles scales with the amount of players in the game so I am confident that’s what’s causing it.
I have absolutely no idea how to fix this. Any help would be greatly appreciated.
LocalScript:
if script.Parent.blowState.Value == 1 then
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("projectileFire")
local blowTip = script.Parent.Body.Tube.TubeTop.CFrame
shootEvent:FireServer(mouse.Hit.p, blowTip)
end
Server Script:
local function shot(player, mouse, blowTip)
local projectiles = player.Backpack.Projectiles:GetChildren()
local projectile = projectiles[1]
local dmgBuff = player.PlayerGui.data.shootBuff.Value
projectile.Parent = game.Workspace
projectile:SetNetworkOwner(player)
projectile.CFrame = blowTip * CFrame.new(2, 0, 0)
local thrust = Instance.new("BodyVelocity")
local direction = blowTip.LookVector
thrust.Parent = projectile
thrust.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
thrust.Velocity = CFrame.new(player.Character.HumanoidRootPart.CFrame.p, mouse).lookVector * 200
projectile.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
if player.Name ~= hit.Parent.Name then
projectile:Destroy()
hit.Parent.Humanoid:TakeDamage(25 + dmgBuff)
end
end
end)
game:GetService("Debris"):AddItem(thrust, 0.1)
game:GetService("Debris"):AddItem(projectile, 3)
end
game.ReplicatedStorage.projectileFire.OnServerEvent:Connect(shot)