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
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! :)