generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Return

Previous Thread :: Next Thread 
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 06:19 PM
What does return do?
Don't tell me to go on wiki, cause I did and I have no clue what it means.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
16 Feb 2014 06:22 PM
return is usually used at the end of a function or to stop a function from running if it finds a particular condition.

Example:

function timestwo(n)
return n*2
end

print(timestwo(2))

if timestwo(2) == 4 then
--code here
end

function imsupposedtostop()
if true then
return end --Will stop here and not print hi
print("hi")
end
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 06:26 PM
...?
So if it's not true then it will print hi?
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 06:29 PM
Bump
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
16 Feb 2014 06:29 PM
Yes
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 06:39 PM
I was looking at how to create admin commands and here was the script. One of the lines is return player. What does that do?


local isAdmin = {["OBF"] = true, ["ArceusInator"] = true, ["amanda12895"] = true}

function findPlayer(name)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower() == name:lower() then
return player
end
end
end

function onChatted(message, player)
if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then
victim = findPlayer(message:sub(6))
if victim and victim.Character then
victim.Character:BreakJoints()
end
end
end


game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message) onChatted(message, player) end)
end)
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
16 Feb 2014 06:41 PM
findPlayer() returns player
say findPlayer return MarioKartAddict

k = findPlayer()
print(k) --> "MarioKartAddict"

it basically makes the function a variable
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
16 Feb 2014 06:45 PM
local isAdmin = {["OBF"] = true, ["ArceusInator"] = true, ["amanda12895"] = true}

function findPlayer(name)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower() == name:lower() then
return player
--if the player is found within all the children of "Players" then
it will return the player
end
end
end

function onChatted(message, player)
if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then
--checks to see if the first 5 characters are "kill/" and if player is
in the table "isAdmin"
victim = findPlayer(message:sub(6))
--looks at the 6th character and beyond then checks to see if it's a player
through the findplayer() method which will return the player
if victim and victim.Character then
victim.Character:BreakJoints()
--Kills the player if there is actually a player
end
end
end


game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message) onChatted(message, player) end)
--If the player that entered chats then it will do the function onchatted
end
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 08:30 PM
So what does return do?
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
16 Feb 2014 08:31 PM
I understand the rest of the scripts but I never scripted using return before. What is it do and when I do I use it?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
16 Feb 2014 08:34 PM
Imagine this, you are in an airport(ROBLOX airport)
and you want to check if the player is a valid.. well.. player.

You do: (Pseudo code Btw)

function checkplayer(player)
if game:find(player)
then
return true
else
return false
end
end

passport.Passed:connect(function(plr) --plr is the player that is trying to pass
plr:Stop
if checkplayer(plr) then --if player passes the test
plr:Go()
end
end)
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
16 Feb 2014 08:37 PM
example of stuff I do with return

function kickScrob(lol) -- start with lol, soon it will be nothing

if lol:IsA('Player') then -- check if it's a player i'm scrobing
lol:Kick() -- SCROB!!11!
else -- if it's not a scrob
print'Scrob cheated') -- print the scrob cheated

end -- end the loop
return nil -- makes the value of lol nothing
end -- end the function

kickScrob('cooldude999921') -- removes me in place of lol , Don't remove me scrob

Medium Script0r
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image