Why is this gun not damaging other players?
I was trying to create a gun that would damage the other team's players. I created a SMGLocalScript inside the gun:
01 | local remoteEvent = ReplicatedStorage:WaitForChild( 'FiringSMGEvent' ) |
04 | local player = game.Players.LocalPlayer |
05 | local mouse = player:GetMouse() |
07 | gun.Equipped:Connect( function () |
10 | mouseConnection = mouse.Button 1 Down:Connect( function () |
12 | while shooting and equipped do |
13 | remoteEvent:FireServer(player.TeamColor, gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p) |
14 | mouse.Button 1 Up:Connect( function () |
24 | gun.Unequipped:Connect( function () |
26 | mouseConnection:Disconnect() |
And created a BulletMaker ServerScript inside ServerScriptService:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local FiringEvent = ReplicatedStorage:WaitForChild( "FiringSMGEvent" ) |
03 | FiringEvent.OnServerEvent:Connect( function (Player, TeamColor, GunPosition, GunOrientation, MousePosition) |
04 | local Bullet = Instance.new( "Part" ) |
05 | Bullet.CanCollide = false |
07 | Bullet.Parent = game.Workspace |
08 | Bullet.Shape = Enum.PartType.Ball |
09 | Bullet.Size = Vector 3. new( 0.5 , 0.5 , 0.5 ) |
10 | Bullet.BrickColor = BrickColor.new( "Smoky grey" ) |
11 | Bullet.CFrame = CFrame.new(GunPosition,MousePosition) |
13 | Bullet.Velocity = Bullet.CFrame.lookVector*Speed |
14 | Bullet.Touched:Connect( function (Hit) |
15 | local Humanoid = Hit.Parent:FindFirstChild( "Humanoid" ) |
16 | if Humanoid and Humanoid.Parent.Name~ = Player.Name and game:GetService(Players).GetPlayersFromCharacters(Hit).Parent.TeamColor~ = TeamColor then |
20 | game:GetService( "Debris" ):AddItem(Bullet, 2 ) |
When I tested the game the BulletMaker ServerScript raised an error: Argument 1 missing or nil