I created a gun script but it allows team killing how can I edit it to remove this possibility?
Here is my code:
--player variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
--gun variables
local gun = script.Parent
local ammo = 100
local magammo = ammo
local reloading = false
local auto = false -- set to false if you do not want the gun to be automatic
local firing = false
local CanChangeFireModes = false
local damage = 80, 100
--^^If set to true the player can press v to change firemodes from auto to semi and semi to auto
local debounce = false
if not game.workspace:FindFirstChild("Bullet") then
local bullet_storage = Instance.new("Folder", workspace)
bullet_storage.Name = "Bullet"
else
--nothing
end
function getBullet()
print(ammo)
if ammo > 0 then
if debounce == false then
debounce = true
ammo = ammo - 1
gun.Handle.Fire:Play()
local mh = mouse.Hit
local B = Instance.new("Part", workspace.Bullet)
B.CFrame = gun.Handle.CFrame + (player.Character.Torso.CFrame.lookVector)
B.CFrame = CFrame.new(B.Position, mh.p)
B.FormFactor = "Custom"
B.Size = Vector3.new(0.2, 0.2, 0.2)
B.BrickColor = BrickColor.Black()
B.CanCollide = false
local velo = Instance.new("BodyVelocity", B)
velo.velocity = B.CFrame.lookVector * 120
velo.maxForce = Vector3.new(math.huge, math.huge, math.huge)
B.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
end
end)
wait(0)
debounce = false
end
end
end
function autofire()
if ammo > 0 then
while firing == true do
if firing == true and ammo <= 0 then
firing = false
end
print(ammo)
wait(0)
gun.Handle.Fire:Play()
local mh = mouse.Hit
local B = Instance.new("Part", workspace.Bullet)
B.CFrame = gun.Handle.CFrame + (player.Character.Torso.CFrame.lookVector)
B.CFrame = CFrame.new(B.Position, mh.p)
B.FormFactor = "Custom"
B.Size = Vector3.new(0.2, 0.2, 0.2)
B.BrickColor = BrickColor.Black()
B.CanCollide = false
ammo = ammo - 1
local velo = Instance.new("BodyVelocity", B)
velo.velocity = B.CFrame.lookVector * 120
velo.maxForce = Vector3.new(math.huge, math.huge, math.huge)
B.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
end
end)
wait(0.005)
end
end
end
mouse.Button1Down:connect(function()
if auto == true then
firing = true
autofire()
else
getBullet()
end
if ammo <= 0 then
print('reloading')
wait(2)
ammo = magammo
end
end)
mouse.Button1Up:connect(function()
if firing == true then
firing = false
end
end)
local uis = game:GetService("UserInputService") -- allows firemode change
uis.InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.V and CanChangeFireModes == true then
if auto == true then
auto = false
else
auto = true
end
end
end)

4 comments
You forgot to identify player as a variable in there..
It's identified at the top of his script, this is just a chunk from the middle
Oh, you actually read his script... Lol ok.
It's literally on line 2...