Lighting bug with flashing lights

Hi, apologies if this is the wrong area to post this to, but I have a gun that has a flashing light when it fires but this lighting bug occurs on some shots, I would like to know if there is a fix or similar because it is very bright on windows and breaks the immersion

Have a look for yourself: (Flashing lights warning)

And here is the script that controls the pointlight: (Tween is declared above)

-- Pointlight
fp.PointLight.Enabled = true
fp.PointLight.Brightness = 20
	
if Tween then Tween:Pause(); Tween:Destroy(); end
Tween = TweenService:Create(fp.PointLight, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Brightness = 0})
Tween:Play()

Any help would be great!

2 Likes

Reduce the size of the PointLight

2 Likes

The code you provided has some errors and issues. Here are the corrections and suggestions:

  1. The fp variable is not defined anywhere in the script. Make sure to define it before using it.
  2. The Tween variable is not defined, and it’s being used in the script. You should define it first.
  3. You’re checking if Tween exists before destroying it, but you should also check if TweenService exists since it’s required for creating new tweens.

Try this code instead:

local fp = script.Parent -- replace with the actual parent element
local TweenService = game:GetService("TweenService")
local Tween

fp.PointLight.Enabled = true
fp.PointLight.Brightness = 20

if Tween and TweenService then
    Tween:Pause()
    Tween:Destroy()
    Tween = nil
end

Tween = TweenService:Create(fp.PointLight, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Brightness = 0})
Tween:Play()

Remember this too; please replace script.Parent with the actual parent element you want to use.

1 Like

I already mentioned that the “Tween” is declared above and fp is also declared but i forgot to mention. Heres the full script:

local ServicePlayers = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage").Shared
local SoundService = require(ReplicatedStorage.SharedServices.SoundService)

UIS.MouseIconEnabled = false

local Viewmodels = ReplicatedStorage.Viewmodels
local v_MRS = Viewmodels.v_TacticalMRS

local Plr = ServicePlayers.LocalPlayer
local FlashGui = Plr.PlayerGui:WaitForChild("Vfx").Flash

local Services = script.Parent.LocalServices
local VMService = require(Services.ViewmodelService)

local Tween = nil;

local function OnFire()
	
	if VMService:IsPlaying("Reload") then return false end
	local fp = VMService.Viewmodel:FindFirstChild("FirePoint",true)
	
	-- Sounds
	SoundService:PlaySoundCopy(fp.Fire)
	
	-- Particles
	fp.FireParticles:Emit(5)
	fp.Explosion:Emit(10)
	fp.Smoke:Emit(20)
	fp.Smoke.Enabled = true
	task.delay(0.5, function() fp.Smoke.Enabled = false end)
	
	-- Gui
	FlashGui.Visible = true
	task.delay(0.05, function() FlashGui.Visible = false end)
	
	-- Pointlight
	fp.PointLight.Enabled = true
	fp.PointLight.Brightness = 20
	
	if Tween then Tween:Pause(); Tween:Destroy(); end
	Tween = TweenService:Create(fp.PointLight, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Brightness = 0})
	Tween:Play()
	

	return true
	
end

VMService:SetViewmodel(v_MRS,
	{
		InternalName = "MRS",
		Animations = {
			Fire = "rbxassetid://134439204500661",
			Reload = "rbxassetid://96770316608587",
			Equip = "rbxassetid://82370762082274",
			Idle = "rbxassetid://79260145684993";
			Run = "rbxassetid://81043873993468";
			WaitUntilLoaded = true;
			InstantAnimations = true;
			RunStops = true;
		};
		Aiming = {AimKeys = {UserInputType = {Enum.UserInputType.MouseButton2}}};
		Fire = {OnFire = OnFire, Keys = {UserInputType = {Enum.UserInputType.MouseButton1}}, Cooldown = 1/10, Auto = true};
		EquipKeys = {KeyCode = {Enum.KeyCode.One}};
		Reload = {OnReload = function() return true end, Keys = {Universal = {Enum.KeyCode.R}}, MaxUses = 30, BaseUses = 15};
		CopyArms = true;
	},
	"1"
)

But the whole script may be irrelevant as that is the only bit that effects the pointlight

1 Like

Unfortunately it still happens, but thanks for the reply!

1 Like

It may has to do with graphic quality. Maybe, if graphic quality is too low, the light render will be worse and less precise.

1 Like

That’s weird: I cant seem to replicate the issue on low graphics but I can on max graphics

1 Like

What’s the bug then (I didn’t understand well)? I’m inclined to think that isn’t a script bug, but instead a graphic one.

1 Like

In the video you can see like projection of the walls through the glass when the pointlight quickly turns on and off - I fairly sure its a graphical bug but It could also be that my pointlight is too bright and thats why I added the script

1 Like

Try reducing the Tween time, it might be causing lighting issues in the environment

1 Like

try to reduce the brightness, i could be wrong, but 20 is extremely bright

2 Likes

Ok, so I tried it for a few values:
0.2 Time: Yes
0.5 Time: Yes
1 Time: No
But 1 Time does look very bad and I don’t really want to resort to that

I also just tried turning the brightness down to 5 and 1, and although it still happens it is to a lesser degree (Image outside is less visible)

1 Like

We all love roblox studio being like this, am I right?

1 Like

We sure do…
Setting the brightness to 0.4 or 0.3 makes the bug almost invisible, and I doubt the average player would notice but the effect for the light is also less visible but is definitely something I am willing to take over what was happening originally

1 Like

My mistake.

The ACTUAL correction is:

    print(v.Name)
    if v:IsA("Tool") and v:FindFirstChild("Tool_Info") and v.Tool_Info:FindFirstChild("Combat") then
        print(v.Name .. " is a combat tool")
        v:Destroy()
    end
end

for i, v in pairs(plr.Character:GetChildren()) do
    if v:IsA("Tool") and v:FindFirstChild("Tool_Info") and v.Tool_Info:FindFirstChild("Combat") then
        local humanoid = plr.Character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            humanoid:UnequipTools()
        end
        v:Destroy()
    end
end

local new_weapon = Weapon_Tools[plr.Data.Weapon.Value]:Clone()
new_weapon.Parent = plr.Backpack


I hope this script is correct.

1 Like

Along with that to get the original effect you can add a ParticleEmitor (I spelt that wrong but don’t care), putting the particles at the end of the barrel

1 Like

We don’t need your chatgpt scripts

1 Like

What?
I mean, this has nothing to do with what I was doing, and even looks AI generated, no offense

1 Like

Yeah I do have some and the effect definitely is not bad, Its just weird this even happens o.o

1 Like

I ran into the same issue, but with something different

1 Like