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

HUD doesn't appear and slowly disappear, why?

Asked by 2 years ago

I am currently trying to make it so when you click E, white appears and then disappears slowly. It isn't doing that

local uis = game:GetService("UserInputService")


local char = script.Parent


local equipRE = game.ReplicatedStorage:WaitForChild("NVGsToggled")


local defaultAmbient = game.Lighting.OutdoorAmbient


function Ball(input, processed)

        uis.InputBegan:Connect(function(input, processed)

        if processed then return end


        if input.KeyCode == Enum.KeyCode.E then


            if not char:FindFirstChild("NVGs") then

                equipRE:FireServer(true)


                game.Lighting.OutdoorAmbient = Color3.fromRGB(74, 74, 74)
                game.Lighting.ColorCorrection.Enabled = true
                local uis = game:GetService("UserInputService")


                local char = script.Parent


                local equipRE = game.ReplicatedStorage:WaitForChild("NVGsToggled")


                local defaultAmbient = game.Lighting.OutdoorAmbient



                uis.InputBegan:Connect(function(input, processed)


                    if processed then return end


                    if input.KeyCode == Enum.KeyCode.E then


                        if not char:FindFirstChild("NVGs") then

                            equipRE:FireServer(true)


                            game.Lighting.OutdoorAmbient = Color3.fromRGB(0, 0, 0)
                            game.Lighting.ColorCorrection.Enabled = true
                            for i = 1, 0, 0.1 do
                                wait(0.01)
                                game.StarterGui.ScreenGui.Frame.BackgroundTransparency = i
                            end
                            wait(0.05)
                            for i = 0, 1, 0.1 do
                                wait(0.1)
                                game.StarterGui.ScreenGui.Frame.BackgroundTransparency = i
                            end


                        else

                            equipRE:FireServer(false)


                            game.Lighting.OutdoorAmbient = defaultAmbient
                            game.Lighting.ColorCorrection.Enabled = false
                        end
                    end
                end)


            else

                equipRE:FireServer(false)


                game.Lighting.OutdoorAmbient = defaultAmbient
                game.Lighting.ColorCorrection.Enabled = false
            end
        end
    end)
end


uis.InputBegan:Connect(Ball)

Ive tried basically anything

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

This is because you are Connecting 3 events if you click E it will fire these 3 events at the same time first it will fire

equipRE:FireServer(true)

then it checks if its already equipped which it is so it fires so it instantly cancels and turn offs NVG

equipRE:FireServer(false)

keep in mind that all of this are fired at the same time if you do prints it would print 3 times instead of 1 Fixed:

local uis = game:GetService("UserInputService")
local TS = game:GetService("TweenService")

local char = script.Parent


local equipRE = game.ReplicatedStorage:WaitForChild("NVGsToggled")


local defaultAmbient = game.Lighting.OutdoorAmbient


function Ball(input, processed)

        uis.InputBegan:Connect(function(input, processed)

        if processed then return end


        if input.KeyCode == Enum.KeyCode.E then


            if not char:FindFirstChild("NVGs") then

                equipRE:FireServer(true)

                game.Lighting.OutdoorAmbient = Color3.fromRGB(74, 74, 74)
                game.Lighting.ColorCorrection.Enabled = true

                local defaultAmbient = game.Lighting.OutdoorAmbient
        TS:Create(game.StarterGui.ScreenGui.Frame,TweenInfo.new(1),{BackgroundTransparency = 0}):Play()
        wait(.05)
        TS:Create(game.StarterGui.ScreenGui.Frame,TweenInfo.new(1),{BackgroundTransparency = 1}):Play()
    else
            equipRE:FireServer(False)
             end
        end
    end)
end


uis.InputBegan:Connect(Ball)

Ad

Answer this question