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

How to change a variable inside a function from outside of the function?

Asked by
Wyqkrn 9
4 years ago

So, I have this function right here.

            BotUp.Button.MouseButton1Click:connect(function()
            if BotUp.ImageColor3 == Color3.fromRGB(255,255,255) then
                if Level.Value >= BottomUpgrade.Level.Value then
                    if Cash.Value >= BottomUpgrade.Cost.Value then
                        UpgradeEvent:FireServer(LocalPlayer,TOWER,"Bottom")
                    end
                end
            end
            end)

It works pretty well. However, I cannot change the variable TOWER from outside of the function and let it take effect inside of the function. If there is a way to do what the function does above and let the rest of the script change TOWER and let it take effect, please tell me! I would be massively thankful!

0
If you declared TOWER above this function, you should have no trouble changing it elsewhere. But you're not showing us where you declare it, nor where you're trying to change it from, so there's not enough here for anyone to really help you. EmilyBendsSpace 1025 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You could declare TOWER as a global variable, in that state all modifications made to it will apply throughout wherever it's called upon, and can even be modified within a function itself.

local TOWER = -- Change this to what you desire and it'll apply below

BotUp.Button.MouseButton1Click:Connect(function()
    UpgradeEvent:FireServer(TOWER, "Bottom") -- Player sent by default
end)
Ad

Answer this question