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.
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:
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.
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.
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.
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.
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)