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
Hi.
Yes, you made a small mistake. It's not critical at all!
Where you used if tc == BrickColor.new("Bright blue") then
at line 15 you did not put any kind of code under it, whereas under the else if tc == BrickColor.new("Really red") then
you did put a code.
This is how you could fix it:
if tc == BrickColor.new("Bright blue") then local Shot = game.ReplicatedStorage:FindFirstChild("BlueShot"):clone() else if tc == BrickColor.new("RedShot") then local Shot = game.ReplicatedStorage:FindFirstChild("RedShot"):clone() end end --Now that we defined the color of shot, we should call a function which will spawn the shot: MakeShot() --Here we will spawn the desired shot. -------------------------------------------------- --Here is the function that we have just called: function MakeShot() 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
Hope this helps!