Alright, as of now, I've pretty much got two variants of a script, both with strange worthwhile events to note. The script is supposed to do as follows:
Here's the first variant:
local Gvis1 = game.Workspace.Tycoon.Tycoon.GuVis1 -- GuVis1 is a boolean value. local mouse = game.Players.LocalPlayer:GetMouse() function onKeyUp( key ) if(string.char( 101 ) == key) then if Gvis1.Value == true then game.Players.LocalPlayer.PlayerGui.ScreenGui.BackFrame.Visible = false Gvis1 = false end if Gvis1.Value == false then game.Players.LocalPlayer.PlayerGui.ScreenGui.BackFrame.Visible = true Gvis1 = true end else print("Key:", key, " Code:", string.byte(key)) end end mouse.KeyUp:connect(onKeyUp)
This variant is kind of strange. It has a notable difference in that when referencing the Gvis1 = false
(or true) it doesn't say ".Value". This one does the following:
Players.Player1.PlayerGui.ScreenGui.GuiTyc1(The script name):11: Attempt to index upvalue 'Gvis1' (a boolean value)
However, if I do place a .Value after Gvis1 = true
(and false), then all it does is this:
In case it couldn't be seen before, this script (which is a localscript) resides inside the Gui being changed while in the players PlayerGui
.
Thanks for reading, and any help is greatly appreciated!
The script gives you that error because you're setting Gvis1 itself to true, instead of it's Value. That's why it's erroring. Here's the fixed code:
local Gvis1 = game.Workspace.Tycoon.Tycoon.GuVis1 -- GuVis1 is a boolean value. local mouse = game.Players.LocalPlayer:GetMouse() function onKeyUp( key ) if key:lower() == "e" then --Simpler to check if the key is "e" instead of using a bytecode if Gvis1.Value == true then game.Players.LocalPlayer.PlayerGui.ScreenGui.BackFrame.Visible = false Gvis1.Value = false --Set the Value to true, not the variable "Gvis" else game.Players.LocalPlayer.PlayerGui.ScreenGui.BackFrame.Visible = true Gvis1.Value = true end end end mouse.KeyUp:connect(onKeyUp)