|
| 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 |
|
|
|
| 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 |
|
|
|
| 09 Jun 2013 02:23 AM |
| ..that's completely irrelevant. |
|
|
| Report Abuse |
|
|
gamert7
|
  |
| Joined: 18 Nov 2008 |
| Total Posts: 4986 |
|
| |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 09 Jun 2013 02:36 AM |
pcall isnt necessary in this situation. and i already notated that a debounce is necessary. |
|
|
| Report Abuse |
|
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
| |
|
|
| 09 Jun 2013 02:38 AM |
| unnecessary ~= irrelevant. |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2013 02:39 AM |
| oh my god sometimes this place is full of twats |
|
|
| Report Abuse |
|
|
| |
|
|
| 09 Jun 2013 03:19 AM |
| None of these worked, the script doesn't give the GUI and no output |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|