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: lualearners advanced test question

Previous Thread :: Next Thread 
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 08:54 PM
this is the question from the advanced portion of lualearners...

When a player touches a brick, it checks to see if the player is approved through a table (hint: make a table, view all the info
and compare it to hit.Parent's name)
If the player isn't approved, the player's joints are broken and a message only viewable to him says: "GO AWAY!"
If the player IS approved, all the bricks in Workspace will be changed to have a CFrame of (.9, .9, .9) and a message will
be viewable to everyone saying PLAYERNAME" Broke this place.".

and this is what i have





01
playerapproved={"cannonssk"}
02
plrnotapp={"Name here"}
03

04
script.Parent.Touched:connect(function(a)
05
local g = game.Players:GetPlayerFromCharacter(a.Parent)
06
c = game.Workspace:GetChildren()
07
for i,v in pairs(playerapproved) do
08
for i = 1,#c do
09
if c[i].ClassName == "Part" then
10
c[i].CFrame = CFrame.new(.9,.9,.9)
11
local msg = Instance.new("Message",game.Workspace)
12
msg.Text=(a.Parent.. " Broke this place.")
13
end
14
end
15
end
16
for i,v in pairs(plrnotapp) do
17
g:BreakJoints()
18
local msg = Instance.new("Message",g.PlayerGui)
19
msg.Text=("GO AWAY")
20
wait(.2)
21
msg:Destroy()
22
end
23
end)
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 08:55 PM
woops, the numbers arent suppose to be there...


playerapproved={"cannonssk"}
plrnotapp={"Name here"}

script.Parent.Touched:connect(function(a)
local g = game.Players:GetPlayerFromCharacter(a.Parent)
c = game.Workspace:GetChildren()
for i,v in pairs(playerapproved) do
for i = 1,#c do
if c[i].ClassName == "Part" then
c[i].CFrame = CFrame.new(.9,.9,.9)
local msg = Instance.new("Message",game.Workspace)
msg.Text=(a.Parent.. " Broke this place.")
end
end
end
for i,v in pairs(plrnotapp) do
g:BreakJoints()
local msg = Instance.new("Message",g.PlayerGui)
msg.Text=("GO AWAY")
wait(.2)
msg:Destroy()
end
end)
Report Abuse
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
20 May 2013 08:56 PM
"advanced test question"
Report Abuse
Xheng is not online. Xheng
Joined: 28 Apr 2013
Total Posts: 158
20 May 2013 08:57 PM
Why does this only apply to LuaLearners... There are good scripters that are as good as coolbob44(Owner of LuaLearners) that can solve this...
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
20 May 2013 08:58 PM
I don't give help to cheaters.
That would be cheating on the test.
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 08:58 PM
i completed the one before it, and its not a test really, its the tutorials, i just dont understand what i did wrong in the script? i reread the tutorials and it doesnt make sense, can u just help me out please
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
20 May 2013 08:59 PM
What's the error?
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 09:02 PM
@xheng, it doesnt apply just to them? or i wulda posted it on their website? i was just tellin u what the question is from
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
20 May 2013 09:02 PM
First of all, you should get rid of the line numbers when posting on the forums. They make the script hard to read.

You are nesting your for loops, which is very bad for this. Also, you only have two conditions: the player is allowed, or he isn't allowed. Which means you only need one permissions table.

First you need to find out if the player is allowed. If his name matches a permission value, you can set a value to true (that is originally set to false) and then save the player's name and break from the loop. Then, you check to see if a permission was matched using the boolean value. If the player did have permission, use the code you currently have to move all the parts of Workspace. Otherwise use the code you currently have to kill the player.


Control structures needed:

function (optional)
if-then
for-do


Methods used:

:remove/:destroy
:getChildren
:IsA (optional)


Properties used:
.Name
.Text
.ClassName (if not using IsA)


Other

Instance.new
pairs


Then again, I argue too much for posts, so maybe I shouldn't help.
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 09:03 PM
data, there isnt an error it just doesnt do what the question asks it to do? i dont know..
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
20 May 2013 09:05 PM
Otherwise use the code you currently have to kill the player (WITHOUT THE FOR LOOP).**
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 09:06 PM
@firefox, ya i was grumpy that day, sorry about that...
and what do u mean with the for commands? that confuses me
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
20 May 2013 09:08 PM
for i = 1, 10 do
for n = 1, 10 do

-- stuff

end
end


That's nesting for loops. The first loop runs 10 times. The second loop runs 10 times per one loop from the first for. This means it runs a total of 100 times.

There is typically no need to nest for loops, so I advise against it.
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 09:11 PM
how do i get around that?... im so brick headed when it comes to tables and for loops
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
20 May 2013 09:17 PM
Read my little paragraph a few more times. I explain exactly what to do in it.

Keep in mind that programming is not about memorizing a language. It's about having the ability to use resources, such as past examples, other people's work, references, etc. to get your program working the way you want it to work. You achieve the same amount when someone just gives you the answer as you do when you memorize specific function names.copy code: absolutely nothing.


Good luck. :)
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
20 May 2013 09:34 PM
thanks! and why did this post get over 10k views o.o
Report Abuse
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
21 May 2013 06:51 AM
F5er, people who constantly refresh the page by holding down F5 key cause views to glitch and spike up

anyways, a solution to the nested for loops would be to make a function checking if the player is an admin instead of re-looping through each player with a nested loop to see if they're admin

for example:

admin = {}

function playerisadmin(playername)
for i = 1, #admin do
if admin[i] == playername then
return true
end
end
return false end

for_,v in pairs(game.Players:GetPlayers()) do
if playerisadmin(v.Name) then
--player is a verified admin, do stuff here
else
--player is not admin, do stuff here
end
end
Report Abuse
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
21 May 2013 06:54 AM
^

the admin table would consist of strings
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
21 May 2013 12:20 PM
Thanks at above! ill try that!
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
21 May 2013 12:46 PM
playerapproved={"cannonssk"}
plrnotapp={"Name here"}

script.Parent.Touched:connect(function(a)
local g = game.Players:GetPlayerFromCharacter(a.Parent)
c = game.Workspace:GetChildren()
for i,v in pairs(playerapproved) do
for i = 1,#c do
if c[i].ClassName == "Part" then
c[i].CFrame = CFrame.new(.9,.9,.9)
local msg = Instance.new("Message",game.Workspace)
msg.Text=(a.Parent.. " Broke this place.")
end
end
end
for i,v in pairs(plrnotapp) do
g:BreakJoints()
local msg = Instance.new("Message",g.PlayerGui)
msg.Text=("GO AWAY")
wait(.2)
msg:Destroy()
end
end)


admin = {"cannonssk"}

function playerisadmin(playername)
for i = 1, #admin do
if admin[i] == playername then
return true
end
end
return false end

for _,v in pairs(game.Players:GetPlayers()) do
c = game.Workspace:GetChildren()
if playerisadmin(v.Name) then
for i = 1,#c do
if c[i].ClassName == "Part" then
c[i].CFrame = CFrame.new(.9,.9,.9)
local msg = Instance.new("Message",game.Workspace)
msg.Text=(a.Parent.. " Broke this place.")
end
end
g:BreakJoints()
local msg = Instance.new("Message",g.PlayerGui)
msg.Text=("GO AWAY")
wait(.2)
msg:Destroy()
end
end
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
21 May 2013 02:43 PM
Got it!!!!!!!!!!!!!


admin = {"cannonssk"}

script.Parent.Touched:connect(function(a)
function playerisadmin(playername)
for i = 1, #admin do
if admin[i] == playername then
return true
end
end
return false end

for _,v in pairs(game.Players:GetPlayers()) do
if playerisadmin(v.Name) then
c = game.Workspace:GetChildren()
for i = 1,#c do
if c[i].ClassName == "Part" then
c[i].CFrame = CFrame.new(.9,.9,.9)
local msg = Instance.new("Message",game.Workspace)
msg.Text=(v.Name.. " Broke this place.")
wait(.5)
msg:Destroy()
end
end
else
v:BreakJoints()
local msg = Instance.new("Message",v.PlayerGui)
msg.Text=("GO AWAY")
wait(.2)
msg:Destroy()
end
end
end)
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
21 May 2013 06:50 PM
is this thread bugged or something? i doubt someone is going to f5 it all the way to 300 thousand
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
21 May 2013 06:51 PM
No, someone just F5 bombed the thread.
Was probably a bunch of people from OT. They seem to hate SH.

Also, I would suggest moving the 'playerisadmin' function outside of the connection, for performance.
Report Abuse
cannonssk is not online. cannonssk
Joined: 02 Mar 2010
Total Posts: 278
21 May 2013 06:56 PM
hmm, ok, alright and thank you!
Report Abuse
GrimReaper5908 is not online. GrimReaper5908
Joined: 13 Feb 2012
Total Posts: 181
18 Aug 2013 11:02 AM
Note: Saying a.Parent Won't Actually Display Anything.
However, Saying a.Parent.Name.. "Broke This Place" Will.

*GrimReaper5908 Broke This Place* :P
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