Alright so I just discovered bools a life saver to making my first game lass glitch-full! so I have theese two pieces of code:
function onClicked(playerWhoClicked) Local Mybool = true game.Workspace.B1.Transparency =100 game.Workspace.PA.Transparency =0 game.Workspace.PB.Transparency =0 game.Workspace.PD.Transparency =0 game.Workspace.PE.Transparency =0 local points = playerWhoClicked.leaderstats.Money points.Value = points.Value-20 end script.Parent.ClickDetector.MouseClick:connect(onClicked)
and
function onClicked(playerWhoClicked) script.Parent.BrickColor = BrickColor.Red() local points = playerWhoClicked.leaderstats.Copper points.Value = points.Value-1 local debrisServ = game:GetService('Debris') local blockLife = 1 local dropper = Instance.new('Part', game.Workspace) dropper.Anchored = false dropper.CFrame = CFrame.new(-133, 9, 93) local dropPart = Instance.new('Part') dropPart.Color = Color3.new(0,0,0) wait(1.2) local points = playerWhoClicked.leaderstats.Money points.Value = points.Value+5 wait(4) script.Parent.BrickColor = BrickColor.Green() end script.Parent.ClickDetector.MouseClick:connect(onClicked)
So I really want to put bools into one of them but when I try to inset one by saying
Mybool= True
but whenever I try it gives me there errors like WOO1 not global, try localising it, expected = got Mybool, I just cannot seem to find how to make one work PLEASE HELP!
Line 2: Local
should be local
.
Also, Transparency
is a float between 0
and 1
.
Second: Put the line local Mybool = false
somewhere at the top of the script and remove the "local
" from line 2, that will allow it to be in scope of both functions.
Bool values in Lua are 'true/false', no caps. (It's not "False", or 'True')
So to declare a global bool value you would use
MyBool = true
(Or false)
Incorporate SwardGames' answer into your code, then make sure each function is closed with an 'end' statement.
A local variable can only be used inside it's indent/block (you could have a bock without indentation). Eg, if you say
function myFunc() local var = 'Hello World' print("made a local variable!") end myFunc() print("Local variable being called outside of block: ") print(var)
You get 'nil' once you run the code, after the 'Local variable being called outside of block:' prints. However, if you want to be able to access the variable anywhere in the code. Just remove the 'local' part.
function myFunc() var = 'Hello World' print("made a local variable!") end myFunc() print("Local variable being called outside of block: ") print(var)