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)

6 comments
I just don't know if it is good to use this many variables in one script.
im not a scripter im a bad lua scripter but that dont look like alot of variables looks pretty good to me but also dont take what im saying im a horrible scripter
Do you really need all those variables?
It would be helpful if I could keep them but I don't know if there is a better way. That is why I am asking the question.
That's a fine amount of variables, except for something like
baseplateName = baseplate.Nameor plrName, those ones are just useless. tycoonName as well it seemsOk thank you