I am scripting a tycoon and am wondering if I am using to many variables and want some tips on how to do it better. Or if it is the correct way to do it please tell me. Here is the variable section in a function:
local plr = hit.Parent.Parent local plrName = plr.Name local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild("PlayerInfo") local specialKey = "User_"..plr.UserId local tycoon = script.Parent.Parent.Parent.Parent local tycoonName = tycoon.Name local savedPurchasedItemsTable local buildLevel = plrInfo.BuildLevel.Value local baseplate = findBaseplate(buildLevel) local baseplateName = baseplate.Name local tycoonBaseplate = game.Workspace.Tycoons:FindFirstChild(tycoonName):WaitForChild(baseplateName) local serverBaseplate = game.ServerStorage.ModelTycoon:FindFirstChild(baseplateName)
The maximum amount of variables you can have in a script is 200.
DEBUNK
Most people on SH think that local variables can be used anywhere in the script, they are WRONG. In Lua 5.1 (Roblox Lua's version of Lua), local variables MUST be used in their native block; otherwise they do not work.