Hello. I use a gun system which I've modified to fire a Part copied from ReplicatedStorage which have premade Trail effects inside them. I'm trying to have it so that if you're on a certain team, a certain bullet will be fired so that blue team will fire blue tracers and red team will fire red tracers etc however only one of the team's bullets actually appear when fired.
script.Parent.Handle.Fire:Play()
local tc = game.Players.LocalPlayer.TeamColor
if tc == BrickColor.new("Bright blue") then
local Shot = game.ReplicatedStorage:FindFirstChild("BlueShot"):clone()
Firing only one type of bullet works perfectly fine however as I said as soon as I try to fire a different one only the second bullet actually appears
script.Parent.Handle.Fire:Play()
local tc = game.Players.LocalPlayer.TeamColor
if tc == BrickColor.new("Bright blue") then
local Shot = game.ReplicatedStorage:FindFirstChild("BlueShot"):clone()
else if tc == BrickColor.new("Really red") then
local Shot = game.ReplicatedStorage:FindFirstChild("RedShot"):clone()
Shots fired in blue team don't appear whilst shots fire in red team do appear. Incase it's important, here is the full Fire function of the gun
function Fire()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local fir = script.Parent.FIRING
local firP = game.Players:GetPlayerFromCharacter(script.Parent.Parent).Character.Humanoid:LoadAnimation(fir)
firP:Play()
script.Parent.Handle.Fire:Play()
local tc = game.Players.LocalPlayer.TeamColor
if tc == BrickColor.new("Bright blue") then
local Shot = game.ReplicatedStorage:FindFirstChild("BlueShot"):clone()
else if tc == BrickColor.new("Really red") then
local Shot = game.ReplicatedStorage:FindFirstChild("RedShot"):clone()
game:GetService("Debris"):AddItem(Shot, 1) -- add it to debris, just in case
Shot.FormFactor = "Custom"
Shot.Name = "Bullet"
Shot.Size = Vector3.new(0.1,0.1,3)
Shot.BrickColor = BulletColour
Shot.TopSurface = "Smooth"
Shot.BottomSurface = "Smooth"
Shot.Transparency = 0
Shot.Material = "Neon"
Shot.Anchored = true
Shot.CanCollide = false
if not script.Parent:findFirstChild("Silencer") then
local light = Instance.new("PointLight")
light.Range = 5
light.Color = OutlineColour.Color
light.Brightness = 2
light.Parent = Shot
end
local mesh = Instance.new("SpecialMesh")
mesh.MeshType = "Brick"
mesh.Parent = Shot
Shot.Parent = workspace
Direct = CFrame.new(script.Parent.Flash.Position , script.Parent.Parent.Humanoid.TargetPoint)
TargetToChange = Direct + Direct.lookVector*1000
OffsetPosition = TargetToChange.p + Vector3.new(math.random(-Accuracy,Accuracy),math.random(-Accuracy,Accuracy),math.random(-Accuracy,Accuracy))
Shot.CFrame = CFrame.new(script.Parent.Flash.Position , OffsetPosition) -- phew, now that's alot of maths
Shot.CFrame = Shot.CFrame + Shot.CFrame.lookVector*1.25
mesh.Scale = Vector3.new(1,1,1)
mesh.VertexColor = Vector3.new(BulletColour.r , BulletColour.g , BulletColour.b)
local selection = Instance.new("SelectionBox")
selection.Parent = Shot
selection.Color = OutlineColour
selection.LineThickness = 0.05
selection.Transparency = 0.5
selection.Adornee = Shot
selection.Visible = true
MoveBullet(Shot)
end
end
end

3 comments
Hey thanks for your response. Forgive me for my lack of knowledge but I'm not sure on how to keep the defined color of the shot localised to the Fire function.
You don't have to keep it. At line 1-5 we did everything. Now script will use only the defined color.
I have seperately defined the color but no matter where I put it all of the Shots in the Fire functions are Unknown globals.