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

Why won't the ColorCorrectionEffect enable unless I hold ''u'' ?

For some reason, the ColorCorrectEffect which I've named ''Sharingan" only turns on (enables) if I'm holding "u", if I let go of the Key "u" the ColorCorrectEffect turns off (disables) which is something I don't want, it's only supposed to disable if I press "u" again after I've already pressed "u" to enable it. Any help?

Script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.Character:FindFirstChild('Humanoid')
local sharingan = game.Lighting.Sharingan


mouse.KeyDown:Connect(function(Key) 
	if Key == "q" then
		sharingan.Enabled = true
		Humanoid.WalkSpeed = 20

	end
end)

mouse.KeyUp:Connect(function(Key)
if Key == "q" then
	sharingan.Enabled = false
	Humanoid.WalkSpeed = 16
end
end)

3 comments

0

KeyDown must be connected with a loop

0

Oh.

1

KeyDown is deprecated, use UserInputService.InputBegan()

1 answer

✓ Accepted answer

Simple invert the Enabled property of the ColorCorrectionEffect upon pressing the key by using not. Also use UserInputService instead of Mouse.

local player = game.Players.LocalPlayer
local Humanoid = player.Character:FindFirstChild('Humanoid')
local sharingan = game.Lighting.Sharingan

game:GetService("UserInputService").InputBegan:Connect(function(iobj, gp)
	if gp then
		return --exit if they are typing in a textbox or such
	end
	if iobj.KeyCode == Enum.KeyCode.U then
		sharingan.Enabled = not sharingan.Enabled --see? like this
	end
end)

1 comment

0

tysm, that makes much more sense.

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