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

Why is this gun not damaging other players?

Asked by 3 years ago

I was trying to create a gun that would damage the other team's players. I created a SMGLocalScript inside the gun:

01local remoteEvent = ReplicatedStorage:WaitForChild('FiringSMGEvent')
02local shooting = false
03local equipped = false
04local player = game.Players.LocalPlayer
05local mouse = player:GetMouse()
06local mouseConnection
07gun.Equipped:Connect(function()
08    equipped = true
09    mouse.Icon = 'rbxassetid://117431027'
10    mouseConnection = mouse.Button1Down:Connect(function()
11        shooting = true
12        while shooting and equipped do
13            remoteEvent:FireServer(player.TeamColor, gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
14            mouse.Button1Up:Connect(function()
15                shooting = false
View all 27 lines...

And created a BulletMaker ServerScript inside ServerScriptService:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local FiringEvent = ReplicatedStorage:WaitForChild("FiringSMGEvent")
03FiringEvent.OnServerEvent:Connect(function(Player, TeamColor, GunPosition, GunOrientation, MousePosition)
04    local Bullet = Instance.new("Part")
05    Bullet.CanCollide=false
06    Bullet.Name="Bullet"
07    Bullet.Parent=game.Workspace
08    Bullet.Shape=Enum.PartType.Ball
09    Bullet.Size = Vector3.new(0.5,0.5,0.5)
10    Bullet.BrickColor = BrickColor.new("Smoky grey")
11    Bullet.CFrame = CFrame.new(GunPosition,MousePosition)
12    local Speed = 500
13    Bullet.Velocity=Bullet.CFrame.lookVector*Speed
14    Bullet.Touched:Connect(function(Hit)
15        local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
View all 21 lines...

When I tested the game the BulletMaker ServerScript raised an error: Argument 1 missing or nil

1
Did it mention the lines? eyad27 8 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try this for your Server Script:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local FiringEvent = ReplicatedStorage:WaitForChild("FiringSMGEvent")
03FiringEvent.OnServerEvent:Connect(function(Player, TeamColor, GunPosition, GunOrientation, MousePosition)
04    local Bullet = Instance.new("Part")
05    Bullet.CanCollide=false
06    Bullet.Name="Bullet"
07    Bullet.Parent=game.Workspace
08    Bullet.Shape=Enum.PartType.Ball
09    Bullet.Size = Vector3.new(0.5,0.5,0.5)
10    Bullet.BrickColor = BrickColor.new("Smoky grey")
11    Bullet.CFrame = CFrame.new(GunPosition,MousePosition)
12    local Speed = 500
13    Bullet.Velocity=Bullet.CFrame.lookVector*Speed
14    Bullet.Touched:Connect(function(Hit)
15        local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
View all 21 lines...
0
Alright, Thank You! sidb0102 17 — 3y
0
You're very welcome! KoalaKo_XD 27 — 3y
Ad

Answer this question