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

Another question about bools!?!

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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.

2 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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

0
Which function do you recommend I use I have tried a few that I thought were correct and came up with the same error Thedestroyer34 25 — 8y
0
Oh, duh. You can also use _G which makes an ACTUAL global variable. You'd have to figure out how to verify which player you are referencing though. captaingector 5 — 8y
0
So I would say: Mybool = true_G??? Thedestroyer34 25 — 8y
0
No, sorry for not being clear. It's _G.MyBool = true. As FrostTaco state. captaingector 5 — 8y
View all comments (3 more)
0
Thedestroyer, please read my answer and it tells you. FrostTaco 90 — 8y
0
THANKS SO MUCH! that question was on my nerves for SOOOOOO long and you solverd it with the _G. thing thanksss! Thedestroyer34 25 — 8y
0
Thedestroyer, you don't have to change it, but I'm just saying I was the original one to post the _G, and I kinda like my reputation. xD Again, if you don't want to, then don't change it :P FrostTaco 90 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Everytime you have the word: Mybool, replace it with _G.Mybool

Answer this question