Changing Lighting.TimeOfDay Creates Objects?

I have a Day and Night Cycle script in my game inside of game.ServerScriptService and I have a local script that gets Descendants added to the game. As the time of day inside lighting changes, the local script picks up objects that are added to the game? but when the day and night cycle script is disabled, I do not get this error in the output.
image
Is there a way for me to get around the error being shown in the output?
I’m prety sure this is triggered by this kind of code since I am not allowed to read that object.

local function OnDescendantAdded(Descendant)
   if Descendant:IsA(InstanceType) then
      --code goes here
   end
end

game.DescendantAdded:Connect(OnDescendantAdded)

Perhaps a pcall ?

The error says something about:
Script 'Players.wevetments.PlayerScripts.ClientControl.Chat Bubble Color', Line 4.

If you could locate that script and go to line 4, the issue probably lies somewhere in there.

The line is if Descendant:IsA(ClassType) then, I’m not allowed to check the class type of the added object, thus the error is thrown in the output.

Hm, if the day and night cycle is the issue ROBLOX made a great tutorial on it, which might be more effective:

1 Like

I don’t have an issue with my day and night cycle script :slight_smile:, I’m just asking if there is a way to go around errors thrown when hidden objects are detected during class checks.

Ah, now I see the issue, the way around it is using a pcall.

1 Like
local function OnDescendantAdded(Descendant)
   if success then
     if Descendant:IsA(InstanceType) then
       --code goes here
     end
   end
end

Success, ErrorMessage = pcall(OnDescendantAdded)

Would it be somthing like this?

I’m not familiar with pcall :confused:

Yes, I believe so, good luck with your project.

Nevermind, I was able to fix it, thanks for the help tho :slight_smile:

local function OnDescendantAdded(Descendant)
 pcall(function()
  --code goes here
 end
end

game.DescendantAdded:Connect(OnDescendantAdded)
1 Like