So I am trying to make a dropper that when purchased uses a bool to tell my dropper to give mere money, here is my code
function onClicked(playerWhoClicked) if Mybool then --The Mybool in this phrase has an error stating that Mybool is a unknown global 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+7 wait(4) script.Parent.BrickColor = BrickColor.Green() else 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 end script.Parent.ClickDetector.MouseClick:connect(onClicked)
That was the dropper this is the upgrader
Mybool = false function onClicked(playerWhoClicked) Mybool = true --This should technically make Mybool a global but it does not 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)
This all works fine, but my droppers value of cash for the ore will not change, sorry if my last question seems similar but I cannot find a way around it.
If I understand correctly, you are trying to reference a variable from one script, inside another. A global variable just means it can be accessed by any block/indentation inside a certain script. If you want to re-use variables through multiple scripts, check out modulescripts. Or you can use a variable object, and reference inside a script.
Here's the first way to fix it that I can think of. If you create a folder inside each player as they join and create a BoolValue inside, you can reference the BoolValue from a script, and have it be accessible from anywhere (so long as FE is off).
Here's a list of stuff you might need: PlayerAdded Instance.new BoolValue
To reference a BoolValue that's in a player, you might use something like
local boolval = player.Values.BoolValue
.
Whereas the 'Values' is the folder, the 'player' is the player object, and of course the 'BoolValue' is the value you are referencing.
OR
as FrostTaco pointed out, and I forgot completely about, as the fact that you can use '_G'. '_G' is a table variable that is shared between all scripts, and can be assigned many different things. Including other tables and functions. Beware of using it in localscripts though, as they are counted as separate Lua instances. _G