Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
KeyDown must be connected with a loop DeceptiveCaster 3761 — 5y
0
Oh. Incinerxte 2 — 5y
1
KeyDown is deprecated, use UserInputService.InputBegan() User#23365 30 — 5y

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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)
0
tysm, that makes much more sense. Incinerxte 2 — 5y
Ad

Answer this question