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: Works once..

Previous Thread :: Next Thread 
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 12:14 PM
button = script.Parent

button.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player ~= nil then
local gui = game.Lighting.Talk:Clone()
local AlreadyHaveGUI = player.PlayerGui:FindFirstChild("Talk")
if AlreadyHaveGUI == nil then
gui.Parent = player:WaitForChild("PlayerGui")
gui.Frame.TextLabel.Text = script.Parent.GUIText.Value

while wait(1) do
local check = player.PlayerGui:FindFirstChild("Zack")
if check then
print('We passed!')
player.PlayerGui.Talk.Frame.Visible = false
print("BOOOOO")

elseif check == nil then
player.PlayerGui.Talk.Frame.Visible = true
print("Done okay?")
end

end
end
end
end)
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
19 Jun 2014 12:22 PM
while wait (1) do will not allow the function to end, since it triggers once every second. Perhaps you should have a script inside Talk with the while loop in it that gets enabled for the player who touched it.

Also, I need to address something:

local gui = game.Lighting.Talk:Clone()
local AlreadyHaveGUI = player.PlayerGui:FindFirstChild("Talk")
if AlreadyHaveGUI == nil then

There's two things that you could do to improve this section of the code.
1) You notice how you clone a Gui with the first variable? Well, let's say that AlreadyHaveGUI isn't nil. Then you have just created a gui that just wastes space.

if AlreadyHaveGui then gui:Destroy () end

That's the other thing I want to address.
2) In conditional statements (used in if statements and repeat until statements), there are shortcuts to referencing booleans, as seen on the Wiki page Writing Clean Code.

if an object does NOT exist, then
if not object then
-- is the same as
if object == nil then

and the same w/ boolean values

debounce = true
if debounce then
-- is the same as
if debounce == true then

Source: http://wiki.roblox.com/index.php?title=Writing_Clean_Code#Booleans
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 12:26 PM
Thank,you. But is there a other way?
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
19 Jun 2014 12:28 PM
Coroutines, but they're ugly.
http://wiki.roblox.com/index.php?title=Coroutines
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 12:35 PM
Eekk okay.

The only reason why I used while wait(1) is because once the GUI's visible when your touching, the script wouldn't function unless you touchit again.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
19 Jun 2014 12:37 PM
Wait, what?
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 12:40 PM
I had to use while wait(1) do because when the gui==nil(The zack GUI), then the script would change the other gui's frame, visible. But when your still touching, it wouldn't function.

I'm very bad at explaining -_-
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
19 Jun 2014 12:43 PM
Oh. That doesn't need a while loop, that needs a debounce!

debounce = true
function Touch (part)
if debounce then
debounce = false
-- stuff
wait (How_Long_You_Want_Someone_To_Wait_Before_Using_This_Again)
debounce = true
end
end
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 12:59 PM
I did this, and it didn't work...

button = script.Parent
db= true
button.Touched:connect(function(part)
if db then
db = false
player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
script.Parent.PlayerName.Value = player.Name
local gui = game.Lighting.Talk:Clone()
local AlreadyHaveGUI = player.PlayerGui:FindFirstChild("Talk")
if not AlreadyHaveGUI then
gui.Parent = player:WaitForChild("PlayerGui")
gui.Frame.TextLabel.Text = script.Parent.GUIText.Value
local check = script.Parent.HasGui
if check.Value == true then
print('We passed!')
player.PlayerGui.Talk.Frame.Visible = false
print("BOOOOO")
elseif check.Value == true then
player.PlayerGui.Talk.Frame.Visible = true
print("Done okay?")
wait(1)
db = true
end
end
end
end
end)

Now it works once,
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
19 Jun 2014 03:19 PM
Please help.
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