I am making a gun in ROBLOX, (working well so far), but to make it look even better. I wanted to add a gun flash effect. How would I do it? If you need the code; read below:

Code:

Ammo = 45

damage = 11

AbleToFire = true

isFiring = true

Player = game:GetService("Players").LocalPlayer
mouse = Player:GetMouse()
mouse.TargetFilter = Player.Character

script.Parent.Equipped:connect(function(eventMouse)
mouse.KeyDown:connect(function(Key)
	if Key == "r" then	
if Ammo <= 44 then
if AbleToFire then
	AbleToFire = false
	
	AbleToFire = false
script.Parent.ReloadSound:Play()
local ReloadAnim = script.Parent.ReloadAnimation
PlayAnim2 = Player.Character.Humanoid:LoadAnimation(ReloadAnim)
PlayAnim2:Play()
wait(1.986)
		PlayAnim2:Stop()		
	Ammo = 45
			Player.PlayerGui.ScreenGui3.Ammo.Value = 45
			AbleToFire = true
end
end
end
end)	
local Weld = script.Parent.GunWeld
PlayAnim = Player.Character.Humanoid:LoadAnimation(Weld)
PlayAnim:Play()	
	Player:WaitForChild("PlayerGui").ScreenGui3.Frame.Visible = true
	eventMouse.Icon = "rbxasset://textures\\GunCursor.png"
end)

script.Parent.Unequipped:connect(function()
	Player:WaitForChild("PlayerGui").ScreenGui3.Frame.Visible = false
PlayAnim:Stop()
PlayAnim2:Stop()
end)

script.Parent.Activated:connect(function()
isFiring = true
repeat wait(.0750)
	if Ammo > 0 and AbleToFire == true then
Ammo = Ammo - 1
Player.PlayerGui.ScreenGui3.Ammo.Value = Player.PlayerGui.ScreenGui3.Ammo.Value - 1
script.Parent.FireSound:Play()
local ray = Ray.new(script.Parent.Handle.CFrame.p, (mouse.Hit.p - script.Parent.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, Player.Character, false, true)
Bullet = Instance.new("Part", workspace)
Bullet.CanCollide = true
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.FormFactor = "Custom"
Bullet.Material = "Neon"
Bullet.CanCollide = false
Bullet.Anchored = true
Bullet.Locked = true
Bullet.Transparency = 0
Bullet.Name = "M4A1Bullet"

local distance = (script.Parent.Handle.CFrame.p - position).magnitude
Bullet.Size = Vector3.new(.0500, .0500, distance)
Bullet.CFrame = CFrame.new(script.Parent.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

game:GetService("Debris"):AddItem(Bullet, 0.1)

if part then
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	
	if not humanoid then
		part.Parent.Parent:FindFirstChild("Humanoid")
	end

if humanoid then
	humanoid:TakeDamage(damage)
end

script.Parent.GripPos = Vector3.new(0.15, -0.4, -0.5)
wait(0)
script.Parent.GripPos = Vector3.new(0.15, -0.35, -0.5)

end
end
until isFiring == false or Ammo == 0
end)



script.Parent.Deactivated:connect(function()
	isFiring = false
end)

4 comments

0

You could use a ParticleEmitter with a flash texture that is enabled after the gun is fired. Just an idea.

0

Okay.

0

ROBLOX offers a variety of mechanisms for visual feedback. You could use particles (including explosions and fire), billboard GUIs, physical parts with translucency, meshes (textured 3D models), lights, or even 'post effects' to modify the whole screen in special ways.

0

Thanks DuckWit, but I already found it out. Thanks though! (I will change the title)