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: What would I need to add to this script, too...

Previous Thread :: Next Thread 
DoctorTempest is not online. DoctorTempest
Joined: 05 Jan 2013
Total Posts: 3838
09 Jun 2013 01:52 AM
Not give the person the Gui if they already have it?

My current script gives the player the Gui when they touch the brick, but multiple times, and I want the script not to give it to them if they already have it.

So far, I have:

function onTouch(hit)
if game.Players:findFirstChild(hit.Parent.Name)~=nil then
player=game.Players:findFirstChild(hit.Parent.Name)
script.Shop:clone().Parent = player.PlayerGui
end
end


script.Parent.Touched:connect(onTouch)

Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
09 Jun 2013 01:56 AM
if not pcall(function() player.PlayerGui.Shop ~= nil end) then --Yes, you still need to add another end for 'if'.
Report Abuse
DoctorTempest is not online. DoctorTempest
Joined: 05 Jan 2013
Total Posts: 3838
09 Jun 2013 02:23 AM
..that's completely irrelevant.
Report Abuse
gamert7 is not online. gamert7
Joined: 18 Nov 2008
Total Posts: 4986
09 Jun 2013 02:25 AM
Try debounce.
Report Abuse
DoctorTempest is not online. DoctorTempest
Joined: 05 Jan 2013
Total Posts: 3838
09 Jun 2013 02:26 AM
Can you explain further?
Report Abuse
ALERIFICALNEUMORAITI is not online. ALERIFICALNEUMORAITI
Joined: 21 Nov 2010
Total Posts: 302
09 Jun 2013 02:27 AM
function onTouch(hit)
if game.Players:FindFirstChild(hit.Parent.Name)~=nil then
local player = game.Players:FindFirstChild(hit.Parent.Name)
if (player["PlayerGui"]:FindFirstChild("Shop")==nil) then
script.Shop:clone().Parent = player["PlayerGui"]
end
end
end
Report Abuse
gamert7 is not online. gamert7
Joined: 18 Nov 2008
Total Posts: 4986
09 Jun 2013 02:29 AM
Going by what you said "It gives them the gui multiple times"

You would add:
debounce = false

function onTouch(hit)
if game.Players:findFirstChild(hit.Parent.Name)~=nil and debounce == false then
debounce = true
player=game.Players:findFirstChild(hit.Parent.Name)
script.Shop:clone().Parent = player.PlayerGui
wait(0.5)
debounce = false
end
end


script.Parent.Touched:connect(onTouch)
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
09 Jun 2013 02:30 AM
What do you mean IRRELEVANT?

It checks if it's there, and pcall is so it doesn't error if it tries to access a null/nil value.

Please explain how it's irrelevant.
Report Abuse
ALERIFICALNEUMORAITI is not online. ALERIFICALNEUMORAITI
Joined: 21 Nov 2010
Total Posts: 302
09 Jun 2013 02:31 AM
A debounce would be necessary but not completely relevant. It would be easier just for the script to check if the player already has the GUI using FindFirstChild rather than to add a debounce, because that doesn't fully solve the problem.
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
09 Jun 2013 02:31 AM
local db = false
function onTouch(hit)
if db then return end
db = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not player.PlayerGui:FindFirstChild("Shop") then
script.Shop:Clone().Parent = player.PlayerGui
end
db = false
end

script.Parent.Touched:connect(onTouch)
Report Abuse
gamert7 is not online. gamert7
Joined: 18 Nov 2008
Total Posts: 4986
09 Jun 2013 02:33 AM
@AL True but, debounce will also help as well with it giving him multiple gui's.
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
09 Jun 2013 02:34 AM
function onTouch(hit)
if game.Players:findFirstChild(hit.Parent.Name)~=nil then
player=game.Players:findFirstChild(hit.Parent.Name)
if not pcall(function() player.PlayerGui.Shop ~= nil end) then
script.Shop:clone().Parent = player.PlayerGui
end
end
end
script.Parent.Touched:connect(onTouch)


--Please tell me how that was irrelevant.
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
09 Jun 2013 02:35 AM
Oh. I didn't explain what I did.. Gamer, I added in a debounce to protect your script from breaking itself (it happens..), and I made it check to see if the shop is already there or not, before giving one to the Player.
Report Abuse
ALERIFICALNEUMORAITI is not online. ALERIFICALNEUMORAITI
Joined: 21 Nov 2010
Total Posts: 302
09 Jun 2013 02:36 AM
pcall isnt necessary in this situation.
and i already notated that a debounce is necessary.
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
09 Jun 2013 02:36 AM
Doctor, rather...
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
09 Jun 2013 02:38 AM
unnecessary ~= irrelevant.
Report Abuse
ALERIFICALNEUMORAITI is not online. ALERIFICALNEUMORAITI
Joined: 21 Nov 2010
Total Posts: 302
09 Jun 2013 02:39 AM
oh my god sometimes this place is full of twats
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
09 Jun 2013 02:41 AM
Like you?

Get out.
Report Abuse
DoctorTempest is not online. DoctorTempest
Joined: 05 Jan 2013
Total Posts: 3838
09 Jun 2013 03:19 AM
None of these worked, the script doesn't give the GUI and no output
Report Abuse
DoctorTempest is not online. DoctorTempest
Joined: 05 Jan 2013
Total Posts: 3838
09 Jun 2013 03:20 AM
nevermind, thanks grim :)
Report Abuse
me6666me is not online. me6666me
Joined: 30 Aug 2011
Total Posts: 698
09 Jun 2013 04:22 AM
Debounce wont work kids

function onTouch(hit)
if game.Players:findFirstChild(hit.Parent.Name)~=nil then
player=game.Players:findFirstChild(hit.Parent.Name)
if not player.PlayerGui:FindFirstChild("Shop")~=nil then
script.Shop:clone().Parent = player.PlayerGui
else
print("Player already has a shop!")
end
end
script.Parent.Touched:connect(onTouch)
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