BrickColor fading to black after key release

I want to make a part gradually fade from white to black, instead of immediately changing to black, but it doesn’t seem to work.

local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
	light.BrickColor = BrickColor.new(255, 255, 255)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
	for i = 1, 10 do
		light.BrickColor = BrickColor.new(255, 255, 255) + (i / 10)
		wait (0.3)
	end
end)

Anything I’m able to change here?

use mousebutton1down to turn on light and moust buttonup to turn it off

There’s already a system put in place with remote events, where it turns on using a certain key, and turns off with the same key when released.

The goal is for it to fade to black as soon as I release the key.


TweenService = game:GetService("TweenService")

goal = {}

goal.Color3 = Color3.new(0, 0, 0)

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light1)

light.Color3 = Color3.new(1, 1, 1)

end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light1)

local tween = TweenService:Create(light, tweenInfo, goal)

tween:Play()

end)

Doesn’t seem to work.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local goal = {}
goal.Color3 = Color3.fromRGB(0, 0, 0)

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
	light.Color3 = Color3.fromRGB(1, 1, 1)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
	local tween = TweenService:Create(light, tweenInfo, goal)
	tween:Play()
end)

Changed things up a bit, no different result.

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light) ---make sure you sent the part you want to light 

whene you fire the event what part you sent in “light”

sent me what you typed in local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LightStart = ReplicatedStorage:WaitForChild("LightStart")
local LightStop = ReplicatedStorage:WaitForChild("LightStop")
local userInputService = game:GetService("UserInputService")
local light = game.Workspace.Lights.LightBTM.light

userInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.KeypadOne then
		game.ReplicatedStorage.LightStart:FireServer(light)
	end
end)

userInputService.InputEnded:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.KeypadOne then
		game.ReplicatedStorage.LightStop:FireServer(light)
	end
end)

The issue with your code is that you are trying to add a number to a BrickColor object, which is not allowed. Instead, you can use the TweenService to gradually change the BrickColor of the light from white to black over a set period of time.

To do this, you will need to import the TweenService module and use its Create function to create a new tween. You can then set the target property of the tween to be the BrickColor of the light, and set the starting and ending values for the tween to be the white and black BrickColor objects, respectively.

Here is an example of how you could do this:

Copy code

local TweenService = game:GetService("TweenService")

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player, light)
    local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
    local tween = TweenService:Create(light, tweenInfo, {BrickColor = BrickColor.new(0, 0, 0)})
    tween:Play()
end)

This will create a tween that will change the BrickColor of the light object from white to black over a period of 5 seconds, using a linear easing style. You can adjust the duration of the tween and the easing style to achieve the effect you desire.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local goal = {}
goal.Color = Color3.fromRGB(0, 0, 0)

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
	light.Color = Color3.fromRGB(1, 1, 1)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
	local tween = TweenService:Create(light, tweenInfo, goal)
	tween:Play()
end)

try the script without changing anything

Tried it, doesn’t seem to change much.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
	light.BrickColor = BrickColor.new(1, 1, 1)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
	local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tween = TweenService:Create(light, tweenInfo, {BrickColor = BrickColor.new(0, 0, 0)})
	tween:Play()
end)

Is this correct?

i used this on part in roblox studio and it works fine

game.Workspace.light.Color = Color3.fromRGB(255, 255, 255) 
wait(1) 
g = {} 
g.Color = Color3.fromRGB(0, 0, 0) 
a = game.TweenService:Create(game.Workspace.light,TweenInfo.new(1),g) a:Play()

The code you posted looks correct and should fade the light from white to black over a period of 5 seconds when the LightStop event is triggered.

If the fade is not working as expected, there could be a few possible causes:

  1. Make sure that the LightStart event is being triggered and the light.BrickColor is being set to white. This is necessary for the fade to work, as the fade will start from the current color of the light.
  2. Check the value of the light.BrickColor property after the LightStart event is triggered. Make sure that it is set to white ( BrickColor.new(1, 1, 1) ) as expected. If it is not set to white, this could be why the fade is not working.
  3. Make sure that the LightStop event is being triggered and the fade tween is being created and played. You can add some debug print statements to your code to verify that these steps are happening as expected.
  4. If the LightStop event is being triggered but the fade is not working, there could be an issue with the tween itself. Make sure that the tweenInfo object is correctly configured and that the tween object is being created and played correctly.

I hope these suggestions help you troubleshoot the issue. Let me know if you have any other questions.

chnage brick color to color = color3.new

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local light = game.Workspace.Lights.LightBTM.light

game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
	light.BrickColor = BrickColor.new(1, 1, 1)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
	local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tween = TweenService:Create(light, tweenInfo, {Color= Color3.new(0, 0, 0)})
	tween:Play()
end)

im pretty sure you have to define the object with a variable instead of defining it in paramaters

local light = game.Workspace.Light

Edit:

reread post, this might be what your looking for then.

Local Script (StarterPlayerScripts)

local uis = game:GetService("UserInputService")

local rem1 = game:GetService("ReplicatedStorage").RemoteEvent
local rem2 = game:GetService("ReplicatedStorage").RemoteEvent2

uis.InputBegan:Connect(function(input, gameprocessed)
	if gameprocessed then return end

	if input.KeyCode == Enum.KeyCode.Q then
		rem1:FireServer()
	end

end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		rem2:FireServer()
	end

end)

Script (ServerScriptService)

local rem = game:GetService("ReplicatedStorage").RemoteEvent
local rem2 = game:GetService("ReplicatedStorage").RemoteEvent2
local light  = game.Workspace:FindFirstChild("light")

rem.OnServerEvent:Connect(function()
	local first = game:GetService("TweenService"):Create(light, TweenInfo.new(1), {Color = Color3.new(0, 0, 0)})

	first:Play()

end)

rem2.OnServerEvent:Connect(function()
	local second = game:GetService("TweenService"):Create(light, TweenInfo.new(1), {Color = Color3.new(1, 1, 1)})

	second:Play()

end)

You cannot change this directly on the server but you can use the server events to send a message to the client that can do this type of change.
game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player,light)
light.BrickColor = BrickColor.new(255, 255, 255)
end)

game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player,light)
– Send to the client to do the change
game.ReplicatedStorage.LightStop.OnClientEvent:InvokeClient(light)
end)

Then on the client side you can do something like this:
game.ReplicatedStorage.LightStop.OnClientEvent:Connect(function(light)
local light = light
for i = 1, 10 do
light.BrickColor = BrickColor.new(255, 255, 255) + (i / 10)
wait (0.3)
end
end)