Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

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.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.