Your main script will never work because it is run only once, so you need to make it run multiple times:
while true do
if script.Parent.Value == true then
script.Parent.Parent.Nightvision.Visible = true
end
wait()
end
But this will "eat" too much resources, possibly making your script laggy. So, we will check the value everytime the value changes:
function check()
if script.Parent.Value == true then
script.Parent.Parent.Nightvision.Visible = true
end
end
game.Workspace.NightVisionGoggles.Part.ClickDetector.MouseClick:connect(check)
Protip 1: You can reduce your script lines if you connect your event directly to the function, like this:
game.Workspace.NightVisionGoggles.Part.ClickDetector.MouseClick:connect(function()
if script.Parent.Value == true then
script.Parent.Parent.Nightvision.Visible = true
end
end)
Protip 2: When comparing booleans, you don't need the == or ~= operator, like this:
game.Workspace.NightVisionGoggles.Part.ClickDetector.MouseClick:connect(function()
if script.Parent.Value then
script.Parent.Parent.Nightvision.Visible = true
end
end)
And let's return to the first script. Something looks obviously wrong:
function open()
game.StarterGui.ToolBar.Inventory.NIGHTVISION.nv.Value = true
end
script.Parent.MouseClick:connect(open)
You are updating everything in the StarterGui, so you will just get the updates once you respawn. To prevent this, you need to make the changes in PlayerGui. Fourtanely, the MouseClick event returns the player who clicked, making the things easier:
script.Parent.MouseClick:connect(function(p)
game.Players:FindFirstChild(p.Name).PlayerGui.ToolBar.Inventory.NIGHTVISION.nv.Value = true
end)
Suddenly, I think we don't need two scripts. We can compile everything all-in-one, at your main script:
script.Parent.MouseClick:connect(function(p)
local inv = game.Players:FindFirstChild(p.Name).PlayerGui.ToolBar.Inventory
if not inv.NIGHTVISION.nv.Value then
inv.NIGHTVISION.nv.Value = true
inv.Nightvision.Visible = true
end
end)
1 comment
Thanks so much!