How would I save colour values into a table to use for later?

Heya!

Currently I’m trying to make a black-out system but I came across the issue where I will need to revert the parts color back to its original after the blackout ends.

It’s half finished since I didn’t know what to do after.

Here’s my current code:

local ObjColors = {}

BlackOut.Event:Connect(function(Mode)
	if Mode == "START" then
		workspace.Audio.BlackOut:Play()
		Lights.Parent = Lighting
		Remotes.Camera.BumpRemaked:FireAllClients()
		
		FogAtmosphere.Parent = Lighting
		TweenService:Create(FogAtmosphere, FogInfo, {Density = 1}):Play()
	
		for _, physicalLight in pairs(PhysicalLights:GetChildren()) do			
			table.insert(ObjColors, physicalLight.Color)
			
			local Tween = TweenService:Create(physicalLight, info, {Color = Color3.fromRGB(0,0,0)})
			Tween:Play()
		end
		
	elseif Mode == "END" then
		workspace.Audio.LightsOn:Play()
		Lights.Parent = workspace:WaitForChild("Map")
		Remotes.Camera.BumpRemaked:FireAllClients()
		
		local TE = TweenService:Create(FogAtmosphere, FogInfo, {Density = 0})
		TE:Play()
		TE.Completed:Wait()
		FogAtmosphere.Parent = ReplicatedStorage

		for _, physicalLight in pairs(PhysicalLights:GetChildren()) do
			
			local ColorToGet = table.find()
			
			local Tween = TweenService:Create(physicalLight, info, {Color = --part where i get the colour back but don't know how})
			Tween:Play()
		end
	end
end)
1 Like

ObjColors[1] will be where the original color is since you inserted the color into the table, given that the color is removed after the end tween using table.remove(ObjColors, 1) or the script only starts once.

Instead of table.insert do ObjColors[physicalLight] = physicalLight.Color and then do:

local ColorToGet = ObjColors[physicalLight]
if not ColorToGet then continue end --in case a light was added after the blackout
--your tween code
2 Likes

What if a instance was removed before the blackout ended? Instead, couldn’t you just store a attribute under the object?

I’ll try this method out.

|| sampletextmaxspacelol ||

It saves the Color3 value, not the Instance so it won’t get affected
For the attribute thing, attributes take longer and a bit more complicated to access than just a table within the script

I believe this method seem to have worked! I’ll do a quick last test incase there may be a fault.

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