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

What is wrong with these BoolValues?

Asked by 5 years ago

So I tried this code where when i press the button 1, a BoolValue (placed under ServerScriptStorage) would update, becoming true instead of false and visa-versa. There are two versions of this script that i tried and do the exact same thing but both have the same problem:

Version 1:

Mouse.KeyDown:connect(function(key) key = key:lower() if key == "1" then if status == false then status = true print(status) elseif Sstatus == true then status = false print(status) end end end)

Version 2:

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input) if input.UserInputType.Name == "Keyboard" then local keyPressed = input.KeyCode if keyPressed == Enum.KeyCode.One then if status == false then status = true
print(status)
elseif status == true then status = false print(status) end end end end

UserInputService.InputBegan:connect(onInputBegan)

So the scripts DO work. I know this because what is printed in the output section is the opposite of what the value was before (true if it was false and false if it was true), which is the goal of the script. However for some weird reason the boolValue dosen't actually update, and other scripts don't pick up a change in Value because of that. I really don't know why this is happening and ive been struggling for the longest time on this. Also all would be solvable in a global script but it cant access :/ Plz help ._.

0
Place your code into a CodeBlock by clicking on the blue Lua icon. This will add two "~~~" lines and your code should be in between them. This will make it easier for us too read. xPolarium 1388 — 5y

Answer this question