What do you want to achieve?
like real eye-adaptive brightness from light to dark
What’s the problem?
there will be obvious flickering problems on the ground
What solutions have you tried so far?
I try but when it reaches 7 it fails he doesn’t stop but continues
local light = game:GetService("Lighting")
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local areasGroup = workspace:WaitForChild("light")
humanoid.Touched:Connect(function(touchedPart)
if touchedPart.Parent == areasGroup then
repeat light.Brightness = light.Brightness + 0.1 wait(0.01) until light.Brightness == 7
touchedPart.TouchEnded:Connect(function(touchEndedPart)
repeat light.Brightness = light.Brightness - 0.1 wait(0.01) until light.Brightness == 3
end)
end
end)
currently used script
local light = game:GetService("Lighting")
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local areasGroup = workspace:WaitForChild("light")
humanoid.Touched:Connect(function(touchedPart)
if touchedPart.Parent == areasGroup then
for i= 3, 7, 0.1 do
light.Brightness = i
wait(0.01)
end
touchedPart.TouchEnded:Connect(function(touchEndedPart)
for i= 7, 3, -0.1 do
light.Brightness = i
wait(0.01)
end
end)
end
end)
Location: It’s a localscript in StarterCharacterScripts
thank for your support. After hours of debug there is one more problem that doesn’t diminish when leaving
local light = game:GetService("Lighting")
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local areasGroup = workspace:WaitForChild("light")
local brightnessDebounce = false
humanoid.Touched:Connect(function(touchedPart)
if brightnessDebounce then return end
if touchedPart.Parent == areasGroup then
brightnessDebounce = true
if brightnessDebounce == true then
repeat light.Brightness = light.Brightness + 0.1 wait(0.01) until light.Brightness >= 7
end
if brightnessDebounce >= 7 then
brightnessDebounce = false
end
touchedPart.TouchEnded:Connect(function(touchEndedPart)
brightnessDebounce = true
if brightnessDebounce == true then
repeat light.Brightness = light.Brightness - 0.1 wait(0.01) until light.Brightness <= 3
end
if brightnessDebounce <= 3 then
brightnessDebounce = false
end
end)
end
end)
put touchedPart in a variable, you need to index through workspace to find it, then the parameter for the function should be Hit and then you can use Hit to find if it is a humanoid that has touched it and then check if the humanoid is the player and then do your brightness code
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
function setLightBrightness(brightness: number)
local tween = TweenService:Create(
lighting,
TweenInfo.new(10, Enum.EasingStyle.Linear),
{Brightness = brightness}
)
tween:Play()
end