Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Could this return script actually work?

Asked by 9 years ago

The Goal

So what I am trying to do is to make a minigame place. It checks if the minigame has a pointbrick and if it does then it means that the minigame is a race. We have to detect when that brick is touched so then when touched it will end the minigame.

The Problem I am not experienced with the 'return' code so can you help with this? The Code

01function round()
02    local minigames = game.Lightning:GetChildren()       
03    local map = minigames[number]
04    local number = math.random(1, #minigames)
05    local spawns = map.Spawns.GetChildren()
06    local pointbrick = map.PointBrick
07    for intermission = 25,1,-1 do
08        game.Workspace.Timer.Value = "Intermission: "..intermission
09 
10    end
11    game.Workspace.Timer.Value = "The game will start shortly."
12    wait(3)
13    game.Workspace.Timer.Value = "Choosing Minigame..."
14    wait(3)
15    game.Workspace.Timer.Value = "Minigame: "..map.Name
View all 62 lines...

2 answers

Log in to vote
2
Answered by
Marios2 360 Moderation Voter
9 years ago

What exactly are you trying to return, and why return anyway? All the returns you have there are pointless. And even without return this script doesn't work.

return is used in functions which are used to process a value and return another. It is also used to cut a statement or loop short.

Here's an example of a function with return:

01--Read game.Players.PlayerAdded first!
02 
03function getId(user) -- In the function we decide to refer to the Player instance as "user"
04    id = user.UserId --We make this variable that gets the player's UserId
05    return id --The variable we got above returns to the event function.
06    --This means that, all lines which are inside the event function and which are after getId below now know a new variable: id.
07end
08 
09game.Players.PlayerAdded:connect(function(player)
10    getId(player) -- The Player instance that was added is taken for processing at the function
11    print(id .. " has joined the server") -- The userid that joined gets printed.
12    --Note that in some cases where you want an interger/number to be a string you must use tostring(number).
13    --For reasons i don't know the script works without it.
14end)

Here's an example ofreturn used as an interruption:

01--Back in my early days on Roblox this is just what follower NPCs were.
02repeat
03--Suppose we have script on here that finds closest player and sets a global variable used below
04    repeat
05        if player == nil then return end -- The repeat loop ends abnormally if we have no player or his character
06        if player.Character == nil then return end
07        script.Parent:MoveTo(player.Character.Torso.Position)
08        wait(0.07)
09    until not (player and player.Character) --The repeat loop ends normally on this case
10until false --This makes a repeat loop endless, provided there is no return for this one

Here's your script fixed (which doesn't need return as anything):

01function round()
02    local minigames = game.Lightning:GetChildren()       
03    local map = minigames[number]
04    local number = math.random(1, #minigames)
05    local spawns = map.Spawns.GetChildren()
06    local pointbrick = map.PointBrick
07    for intermission = 25,1,-1 do
08        game.Workspace.Timer.Value = "Intermission: "..intermission
09 
10    end
11    game.Workspace.Timer.Value = "The game will start shortly."
12    wait(3)
13    game.Workspace.Timer.Value = "Choosing Minigame..."
14    wait(3)
15    game.Workspace.Timer.Value = "Minigame: "..map.Name
View all 59 lines...

I hope i helped with both the script and understanding return.

0
Dude... look down. NeonicPlasma 181 — 9y
0
Dude, the one I want is cut short. NeonicPlasma 181 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

So I saw the answer. But you do realize that the game is a minigame place and that it will actually go like this?

01function round()
02    local minigames = game.Lightning:GetChildren()       
03    local map = minigames[number]
04    local number = math.random(1, #minigames)
05    local spawns = map.Spawns.GetChildren()
06    local pointbrick = map.PointBrick
07    for intermission = 25,1,-1 do
08        game.Workspace.Timer.Value = "Intermission: "..intermission
09 
10    end
11    game.Workspace.Timer.Value = "The game will start shortly."
12    wait(3)
13    game.Workspace.Timer.Value = "Choosing Minigame..."
14    wait(3)
15    game.Workspace.Timer.Value = "Minigame: "..map.Name
View all 62 lines...
1
Yes, i do. And i forgot to make the minigame loop, my bad. Well the only mistake in the script i gave you is that i forgot to make it loop, is it really that good of a reason to insult? Marios2 360 — 9y
0
Anyways, I'm just gonna upvote every comment you put. NeonicPlasma 181 — 9y

Answer this question