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: How could I make a script run just once?

Previous Thread :: Next Thread 
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
16 Sep 2012 04:54 AM
I'm making a GUI that appears when you step on a certain brick, but I want the GUI to appear only once, but I have no idea how to do that. Can I have some help please?:D
Report Abuse
sycips is not online. sycips
Joined: 21 Mar 2011
Total Posts: 1368
16 Sep 2012 05:12 AM
Well try this: if the player hits the brick, it first checks for the GUI. If the GUI is already opened the script does nothing. Else the script opens the GUI.
If textlabel.Visible == false then textlabel.Visible = true end
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
16 Sep 2012 05:33 AM
function onTouched()
script.Disabled = true
--Rest of script goes here
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
16 Sep 2012 06:52 AM
Add a debounce.
Report Abuse
sycips is not online. sycips
Joined: 21 Mar 2011
Total Posts: 1368
01 Oct 2012 04:12 AM
you dont have to add a debounce! cause it doesn't matter if the event connects like 2 times at once to the function that makes the gui appear. cause it'll stay visible after touching!
Report Abuse
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
01 Oct 2012 06:38 AM
You could do

Connect = .Touched:connect()
Connect:disconnect()
Report Abuse
technoguyx is not online. technoguyx
Joined: 05 Dec 2008
Total Posts: 8286
01 Oct 2012 07:40 AM
sycips is right. Simply check whether the GUI exists - all the other options people have suggested may make the script seem "broken" to other players.

--pseudocode-ish example
GUI = script.Parent.DefineThisPls

script.Parent.Touched:connect(
function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

if plr and plr.PlayerGui then --check if player exists

if not plr.PlayerGui:FindFirstChild(GUI.Name) then --proceed only if GUI isn't copied yet

local g = GUI:Clone()
g.Parent = plr.PlayerGui

end

end

end)
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