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 » Scripters
Home Search
 

Re: Help with a very simple script involving a for loop.

Previous Thread :: Next Thread 
KlinkStudios is not online. KlinkStudios
Joined: 31 Oct 2013
Total Posts: 563
20 Jun 2015 10:02 PM
It says "Syntax error: Expression must be a variable or a field" when I try to run this script:

function onButtonClicked()
for i,v in pairs do (game.Players.LocalPlayer.PlayerGui.DefaultGUI:GetChildren())
if v.Name = "DoorOptions" then
v:Destroy()
end
end
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

What's wrong?

u sicko!
Report Abuse
DrSaint is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
20 Jun 2015 10:05 PM
Try OnClicked instead of OnButtonClicked
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
20 Jun 2015 10:06 PM
@DrSaint
WRONG

The error is this:

if v.Name = "DoorOptions" then

It should be

if v.Name == "DoorOptions" then
Report Abuse
KlinkStudios is not online. KlinkStudios
Joined: 31 Oct 2013
Total Posts: 563
20 Jun 2015 10:06 PM
...That did literally nothing. I should mention that the error is on line 2.

u sicko!
Report Abuse
KlinkStudios is not online. KlinkStudios
Joined: 31 Oct 2013
Total Posts: 563
20 Jun 2015 10:06 PM
Anyway, thanks for pointing out that error for me.

u sicko!
Report Abuse
DrSaint is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
20 Jun 2015 10:07 PM
@CLONE

AH EEH GAD DONT SCREAM AT ME I HAVE SENSITIVE EARS
Report Abuse
DrSaint is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
20 Jun 2015 10:08 PM
@Klink

Always post the error line. Makes it much easier and faster to track down. Doesn't make me look like an idiot too.
Report Abuse
KlinkStudios is not online. KlinkStudios
Joined: 31 Oct 2013
Total Posts: 563
20 Jun 2015 10:11 PM
Anyway, what's wrong with my script? Am I using GetChildren() wrong?

u sicko!
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
20 Jun 2015 10:13 PM
"do" goes at the end of the line

for i,v in pairs(game.Players.LocalPlayer.PlayerGui.DefaultGUI:GetChildren()) do

pairs is a function that accepts the table you want to loop over
pairs(tab)
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
20 Jun 2015 10:13 PM
Oh wait I missed that too.
It should be:

function onButtonClicked()
for _,v in pairs(game.Players.LocalPlayer.PlayerGui.DefaultGUI:GetChildren()) do
if v.Name == "DoorOptions" then
v:Destroy()
end
end
end

script.Parent.MouseButton1Click:connect(onButtonClicked)
Report Abuse
KlinkStudios is not online. KlinkStudios
Joined: 31 Oct 2013
Total Posts: 563
20 Jun 2015 10:14 PM
Thanks, that helps a lot.

u sicko!
Report Abuse
DrSaint is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
20 Jun 2015 10:14 PM
Oh see I wasn't even close, I make myself look like an idiot lmao
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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