I was trying to create a gun that would damage the other team's players. I created a SMGLocalScript inside the gun:
local remoteEvent = ReplicatedStorage:WaitForChild('FiringSMGEvent') local shooting = false local equipped = false local player = game.Players.LocalPlayer local mouse = player:GetMouse() local mouseConnection gun.Equipped:Connect(function() equipped = true mouse.Icon = 'rbxassetid://117431027' mouseConnection = mouse.Button1Down:Connect(function() shooting = true while shooting and equipped do remoteEvent:FireServer(player.TeamColor, gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p) mouse.Button1Up:Connect(function() shooting = false end) wait(0.1) end end) end) gun.Unequipped:Connect(function() equipped = false mouseConnection:Disconnect() end)
And created a BulletMaker ServerScript inside ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local FiringEvent = ReplicatedStorage:WaitForChild("FiringSMGEvent") FiringEvent.OnServerEvent:Connect(function(Player, TeamColor, GunPosition, GunOrientation, MousePosition) local Bullet = Instance.new("Part") Bullet.CanCollide=false Bullet.Name="Bullet" Bullet.Parent=game.Workspace Bullet.Shape=Enum.PartType.Ball Bullet.Size = Vector3.new(0.5,0.5,0.5) Bullet.BrickColor = BrickColor.new("Smoky grey") Bullet.CFrame = CFrame.new(GunPosition,MousePosition) local Speed = 500 Bullet.Velocity=Bullet.CFrame.lookVector*Speed Bullet.Touched:Connect(function(Hit) local Humanoid = Hit.Parent:FindFirstChild("Humanoid") if Humanoid and Humanoid.Parent.Name~=Player.Name and game:GetService(Players).GetPlayersFromCharacters(Hit).Parent.TeamColor~=TeamColor then Humanoid.Health-=10 end end) game:GetService("Debris"):AddItem(Bullet,2) end)
When I tested the game the BulletMaker ServerScript raised an error: Argument 1 missing or nil
Try this for your Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local FiringEvent = ReplicatedStorage:WaitForChild("FiringSMGEvent") FiringEvent.OnServerEvent:Connect(function(Player, TeamColor, GunPosition, GunOrientation, MousePosition) local Bullet = Instance.new("Part") Bullet.CanCollide=false Bullet.Name="Bullet" Bullet.Parent=game.Workspace Bullet.Shape=Enum.PartType.Ball Bullet.Size = Vector3.new(0.5,0.5,0.5) Bullet.BrickColor = BrickColor.new("Smoky grey") Bullet.CFrame = CFrame.new(GunPosition,MousePosition) local Speed = 500 Bullet.Velocity=Bullet.CFrame.lookVector*Speed Bullet.Touched:Connect(function(Hit) local Humanoid = Hit.Parent:FindFirstChild("Humanoid") if Humanoid and Humanoid.Parent.Name~=Player.Name then Humanoid.Health-=10 end end) game:GetService("Debris"):AddItem(Bullet,2) end)