I have a tycoon idea I want to try out but, I’m not the best at scripting. So I would like to know if I should put a script in each button that would allow certain parts of a tycoon to appear when you touch it, or if I should somehow put it in one script. I looked at some videos on making a tycoon from scratch and they handled all the buttons in one script. When I tried to replicate this, it did not work. My main concerns with putting a script in each button is the lag but I find it easier than the other option. So any suggestions on which is better and how I could do it.
You can do either or, but if you’re going to make it where walking on a button makes you purchase a tycoon to make it appear, it’s best to try to do it in one script.
The Touched connection can cause lag especially if you do not debounce it and/or if you do not remove the touch connection once used correctly. Doing it with one script will allow you to handle that a lot more easier than putting a script inside of each button. Also you’ll be able to handle your tycoon buttons a lot more easier doing it in one script than having to micro-manage 100+ scripts if you have 100+ buttons.
You can get these buttons easily by doing a index such as doing :GetChildren() or :GetDescendants() and it’ll return an array/table you can use to find all of the buttons you want.
If I did everything in one script, how would I set that up?
Let’s say for example you have a tycoon model and you have your tycoon buttons and all of your tycoon buttons are in a model called ‘TycoonButtons’ you can set everything up as such:
local ButtonTouchCooldown = 0.25
for index, button in pairs (game.Workspace.Tycoon.TycoonButtons:GetChildren()) do
if button and button.Name == "TycoonButton" then --Set up an argument to figure out a special condition to identify your tycoon buttons
local ButtonPurchased = false
local OnButtonTouchConnection
local function ButtonHit(Hit)
if ButtonPurchased == false then
ButtonPurchased = true
OnButtonTouchConnection:Disconnect() --This will stop the touch function from firing to help reduce touch lag
wait(ButtonTouchCooldown)
OnButtonTouchConnection = button.Touched:Connect(ButtonHit) --This will renable the touch function again.
ButtonPurchased = false
end
end
OnButtonTouchConnection = button.Touched:Connect(ButtonHit)
end
end
Try watching the Dutch Developer’s video on it (Youtube) or look at the video that zed tycoon kit but remake it