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: Highly confused. Need help with simple script.

Previous Thread :: Next Thread 
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
23 Feb 2014 12:25 PM
I have created this script in order to make multiple "counter pads" that increase the text number of a GUI by 1 each time it is hit, and only once. Example:

There are three pads on the floor. I touch one of them, and it disappears. It added one to my counter GUI. I then step over the other two. They disappear, each adding one to my counter. My counter now reads "3".

However, when I step on one, it disappears, but does not add to my counter. I have checked to make sure the references are correct.

Please tell me what I am doing wrong so I can fix it, rather than just giving me a re-written script.

Thanks.

touches = 0

function onTouch(hit)
local touch_once = true
if touch_once == true then
touches = touches + 1
game.StarterGui.ControlGUI.game_counter.Text = touches
touch_once = false
if touch_once == false then
game.Workspace.counter_pad:Destroy()
end
end
end

script.Parent.Touched:connect(onTouch)
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
23 Feb 2014 12:31 PM
You changed the text of something in the StarterGui. You need to change the text of the thing in your playerGui.
Report Abuse
StackEnd is not online. StackEnd
Joined: 20 Oct 2008
Total Posts: 672
23 Feb 2014 12:32 PM
One major error I see is that you're changing the GUI in StarterGui instead of the player's PlayerGui. Changing the StarterGui will only affect the Gui the player respawns with.

Also, there's no need for that "touch_once" variable. It would be a lot more efficient to re-write the code.

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent:destroy()
end)
Report Abuse
StackEnd is not online. StackEnd
Joined: 20 Oct 2008
Total Posts: 672
23 Feb 2014 12:33 PM
Whoops

it should be
game.Players:GetPlayerFromCharacter(hit.Parent).ControlGUI.game_counter.Text = ControlGUI.game_counter.Text + 1
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
23 Feb 2014 12:34 PM
+ an extra end ^^^^
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
23 Feb 2014 07:56 PM
Thanks! But how do I understand and incorporate that into my current script? I'm still new to Lua.
Report Abuse
Kyrothehero is not online. Kyrothehero
Joined: 14 Aug 2012
Total Posts: 306
23 Feb 2014 07:57 PM
...
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
23 Feb 2014 08:10 PM
Why the dots? I'm just trying to learn and I am coding a game for a competition that is due in a week.
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