Hello Everyone! So I made a textbutton which creates parts in game and I made a textbox to and if we enter a number in the textbox, those many parts should spawn. But how do I do it?
Should I type like local times = 5
repeat(times).Pls tell me how to do it.
local Textbox = script.Parent
Textbox.InputEnded:Connect(function()
for i=1,tonumber(Textbox.Text) do
--do something
end
)
You seem to be pretty new to coding, so I’ll actually explain in a beginner-friendly fashion.
First, you will want to use a numeric for loop. A numeric for loop allows you to repeat code a set amount of times.
for i = 0, 100, 2 do -- go from 0 to 100 in steps of 2
print(i) -- print the number
end
The first number, 0, is where you want to start. The second number is the goal. It’s where you want to end. The third number is the increment (or step), which is how much to add to the start after each cycle of the loop. This value defaults to 1, so if you just want to go up by 1 you can just leave it blank.
You can count down negatively as well, but remember to specify a negative step!
for i = 100, 0, -1 do
print(i) -- go from 100 to 0 in steps of -1
end
Alright, that aside, you said you had a TextButton:
So I am assuming you want the player to input a number of parts to create in the TextBox, so they can click the TextButton to create however many parts they specified.
I went ahead and made a place with the scripts, explaining each one in depth. I hope this helps
part_creator.rbxl (28.0 KB)
Oh thank you c:.I will see it and try to understand it.
Sorry but I did not get whats gsub function and how do the client and server scripts communicate.FireServer(a variable) and how do the script recieves it.OnServerEvent:Connect(function(the variable I sent or player)