Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i enable and disable lighting?

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.C then
local Color = (Instance.new("ColorCorrectionEffect")) 
  Color.Name = "BlackAndWhite" 
  Color.Brightness = 0 
  Color.Contrast = 0
  Color.Enabled = true 
  Color.Saturation = -1 
  Color.TintColor = Color3.fromRGB(255,255,255) 
  Color.Parent = game.Lighting 
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://YourOwnID'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
 end
end)

UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.C then

  PlayAnim:Stop()
 end
end)

so thats my script in characterscripts but idk how to disable it under the (input.KeyCode ==Enum.KeyCode.C then) idk what to do to disable the lighting effect

1 comment

0

delete it

1 answer

You need to create the Color variable outside of the UserInputService connections, so that they both have access to it. Then to disable it you can destroy it in InputEnded.

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

-- Create the variable here
local Color

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		-- Assign the variable here
		Color = (Instance.new("ColorCorrectionEffect")) 
		Color.Name = "BlackAndWhite" 
		Color.Brightness = 0 
		Color.Contrast = 0
		Color.Enabled = true 
		Color.Saturation = -1 
		Color.TintColor = Color3.fromRGB(255,255,255) 
		Color.Parent = game.Lighting 
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://YourOwnID'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		-- Now you can destroy it here
		-- To be safe, check that it has been assigned first
		if Color then
			Color:Destroy()
		end
	
		PlayAnim:Stop()
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.