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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
| |
|
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 |
|
|
| |
|
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 |
|
|