How would I be able to change a decal at night?

I’m currently trying to make a scope that has a reticle, and I want the reticle to change at night to turn into green.
image
I already have the texture of the Night reticle, I just need to find a way to actually make it work.
image
This part is a child of a model, which shouldn’t affect much.


TLDR: I want to make a decal change color at night, I have the texture made and I just need a way to do the script. Any concept would be nice so I can piece together the script.

Have a script that checks the value in Lighting, for Minutes
if Minutes is < a certain value and > than a certaint value, then its day
otherwise its night
apply the decal depending on which one of these it is

1 Like

How would I be able to do this?
Nevermind.

local dawn = 360
local evening = 1200
local lastState = ""
while true do
  local minutes = game.Lighting:GetMinutesAfterMidnight()
  if minutes > dawn and minutes < evening then --its day
    if lastState ~= "day" then
      --change decal to day
      lastState = "day"
    end
  else --its night
    if lastState ~= "night" then
      --change decal to night
      lastState = "night"
    end
  end
  wait(1)
end
1 Like

Normally in a case like this I’d put 2 decals in the view, then make them alternate between transparency 1 and 0 to change which is visible.

1 Like

Changing textures is basically the same thing.

1 Like
--18/6 = night
--any other time = day
--used geographiclatitude = 28.244

local Reticle = script.Parent.Decal

local Reticle2 = script.Parent.Parent.Reticle2.Decal


	if game.Lighting.ClockTime >= 18 then

	Reticle.Transparency = 1
	Reticle2.Transparency = 0
	
end

if game.Lighting.ClockTime < 18 then
	
	Reticle.Transparency = 0
	Reticle2.Transparency = 1
	
end

I tried doing something like this due to @Scottifly’s suggestion and it has no errors with output but it just doesn’t change the transparency at all. Any reason it wouldn’t?

It was due to the day and cycle night script I was using. It works now. Thanks for the help mates!

Is there a chance this doesn’t work for models in ReplicatedStorage? I am using the ACS Gun Engine and it doesn’t seem to change anything at all.

The gun the player is using should be stored in the Player’s backpack (or however the ACS gun engine does it) while playing, so you can’t reference that model in replicated storage.
Your script has to reference the actual gun model the player is using, not where it was cloned from.

1 Like

How so?

ACS works by adding a tool to your backpack and has set animations and rules/options of the gun. The gun model itself is located in ReplicatedStorage, not in the player model which is server sided meaning it doesn’t show in the view model just other players.

if you know the name of the gun, and you have it equipped in your hand, it is most likely under Character.

so in local script

local player = game.Players.LocalPlayer
local character = player.Character
local gun = character:FindFirstChild("<name of gun>")
2 Likes

So as @SelDraken said, you have to find out exactly where the gun model is a child of your player. Your script has to reference that location.
Remember that your local player is parented to the workspace, not the Player Service folder.

1 Like

Ah I get what you mean,
that is already done by putting the script in ReplicatedStorage. Due to ACS being weird, it doesn’t update till you reequip after moving a part or making any changes (manually at least). But with the script, it doesn’t show either way.

It seems to work for the server, but the viewmodel doesn’t change.
Found the location of viewmodel (camera), it actively changes when I manually do it. But the script decides to not work for god knows what reason. No output errors.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.