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

Why isnt this nighvision GUI tool script working? What did I do wrong?(If statements)

Asked by
EpicLilC 150
8 years ago

I'm trying to make night vision googles and when you equip a tool called "NightVision" a transparent green gui comes up. For some reason this script isn't working. What did I do wrong?

    if game.StarterPack.NightVision.Equipped = true then
        local gui = Instance.new("ScreenGui",game.StarterGui)
    local frame = Instance.new("Frame",game.StarterGui.gui)
    frame.Size = UDim2.new(0.999, 0,0.994, 0)
    frame.BackgroundColor3 = UDim2.new(0, 212, 0)
    frame.BackgroundTransparency = .6
    end
    if game.StarterPack.NightVision.Equipped = false then
        game.gui:Remove()
    end
0
Just saying, the question below works, but for future references if statements require 2 '==' DeveloperSolo 370 — 8y

1 answer

Log in to vote
3
Answered by
TofuBytes 500 Moderation Voter
8 years ago
Edited 8 years ago

Hi! That's a good try to detect the tool getting equipped, but it won't work! Instead use Equipped and Unequipped. These two are built into the tool to call an event function. Given so, this will call from a script located within the tool itself. I've also fixed your BackgroundColor3. Make sure to use Color3.fromRGB when using RGB color format that aren't between 0-1.

script.Parent.Equipped:connect(function()
    gui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
    frame = Instance.new("Frame",gui)
    frame.Size = UDim2.new(0.999, 0,0.994, 0)
    frame.BackgroundColor3 = Color3.fromRGB(0, 212, 0)
    frame.BackgroundTransparency = .6
end)

script.Parent.Unequipped:connect(function()
    gui:Destroy()
end)

Hopefully this helps! :)

Ad

Answer this question