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

why or how should i use these statements/strings?

Im a beginner, ive scripted in 3/4 days and i have a question (roblox studio)

in which part of game development do u use the strings:

if statements

els if

while true do

i just cant understand how and why i should use em

and do anybody have any trainings or challenges i can do?

2 comments

0

Use code blocks.

0

u suck my nuts thats how and when? 5 minutes or more, even if i splooj early

1 answer

✓ Accepted answer

Hi, Lordmunga! So I will give you some examples in common situations.

If statements:

So, let's say you have prepared a shop and some leader stats. You can put this script inside the button.

local Button = script.Parent --The button

Button.MouseButton1Click:Connect(function (Player) --Gets the player who clicked the button
if Player.leaderstats.Money == 10 then
print("Successfully purchased!") --If the player's money is enough to buy the item, a message in the console will print "Successfully purchased!"
end
end)

Elseif:

So, what if the money is not enough? This is where elseif and else come in.

local Button = script.Parent --The button

Button.MouseButton1Click:Connect(function (Player) --Gets the player who clicked the button
if Player.leaderstats.Money == 10 then
print("Successfully purchased!") --If the player's money is enough to buy the item, a message in the console will print "Successfully purchased!"
elseif -- We could actually just use else but we are using elseif just to double-check.
Player.leaderstats.Money < 10 then
print("Insufficient funds") -- If the player doesn't have enough money, a message will be printed in the console.
end
end)

While loops:

Let's say you want to spawn a part every second in the same place. You could use while loops.

while true do
local Part = Instance.new("Part", workspace)
Part.BrickColor = BrickColor.new("Bright blue")
end

Thanks for reading until the end.

If I helped don't forget to accept the answer!

4 comments

0

To accept the answer, click "Accept Answer" below the answer.

0

Well done, good examples. I just want to add some exercises for Lordmunga to do, so he could master these because that is what he asked for as well. For a while loop, try something basic like a day/night cycle. For your if/elseif statements, you can try to see if there is a specific part in the game and if there is, it can print something. Else, you can make it print something else.

0

thx for the help

0

No problem! Always happy to help!

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