|
| 26 Oct 2016 04:23 PM |
I have a script here, that is supposed to give you a GUI (once) when a part is touched. However, It seems to give out the GUI more than once and they overlay on top of each other. I can't figure out how to only have a single GUI be given to me. (I'm bad at explaining, I really hope that made sense..?)
function onTouch(hit)
local ptt = game.Players:playerFromCharacter(hit.Parent) if ptt == nil then return end local wfp = script.Parent:findFirstChild("GuiName"):clone() if wfp == nil then return end wfp.Parent = ptt.PlayerGui
end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
| |
|
Lordux
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 610 |
|
|
| 01 Nov 2016 05:11 PM |
Add a debounce.
If you don't know what that is it could just be a variable. Your function would only add the GUI if the debounce is ready. |
|
|
| Report Abuse |
|
|
|
| 01 Nov 2016 05:13 PM |
| I'm so sorry to bother anyone with this, I can't figure out how to add the debounce. The script keeps breaking. |
|
|
| Report Abuse |
|
|
Lordux
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 610 |
|
|
| 01 Nov 2016 11:56 PM |
Debounce = true function onTouch(hit) If Debounce == true then Debounce = false local ptt = game.Players:playerFromCharacter(hit.Parent) if ptt == nil then return end local wfp = script.Parent:findFirstChild("GuiName"):clone() if wfp == nil then return end wfp.Parent = ptt.PlayerGui . wait(5) Debounce = true end end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
|
| 02 Nov 2016 12:00 AM |
| I hate when people use a debounce on things like this that doesn't check which player needs to not activate it again. Its annoying when you have to wait 5 seconds because someone else just touched it, and possible not even get to use it if it happens to pick them to activate again. |
|
|
| Report Abuse |
|
|
|
| 04 Nov 2016 09:15 PM |
| ^ Is there anything else you recommend to solve the problem other than a debounce then? |
|
|
| Report Abuse |
|
|
|
| 04 Nov 2016 09:17 PM |
make it so that if the player already has the Gui the new one that gets cloned is instantly destroyed
or you can save a list of the players who have the gui in a table
or you can use boolvalues for the players to detect who already has the gui
lots of ways |
|
|
| Report Abuse |
|
|
|
| 04 Nov 2016 09:20 PM |
| Thank you so much for your time Lordux, the script helped !! |
|
|
| Report Abuse |
|
|
|
| 04 Nov 2016 09:33 PM |
Wouldn't even need a debounce. I added: if ptt.PlayerGui:FindFirstChild("GuiName") then return end I tested it also
local scr=script.Parent local function onTouch(hit) if hit.Parent:WaitForChild("Humanoid") then local ptt=game.Players:playerFromCharacter(hit.Parent) if ptt.PlayerGui:FindFirstChild("GuiName") then return end local wfp=scr:FindFirstChild("GuiName"):Clone() if wfp==nil then return end wfp.Parent=ptt.PlayerGui end end
|
|
|
| Report Abuse |
|
|
|
| 04 Nov 2016 09:34 PM |
Roblox takes out the last line when copypasta great
local scr=script.Parent local function onTouch(hit) if hit.Parent:WaitForChild("Humanoid") then local ptt=game.Players:playerFromCharacter(hit.Parent) if ptt.PlayerGui:FindFirstChild("GuiName") then return end local wfp=scr:FindFirstChild("GuiName"):Clone() if wfp==nil then return end wfp.Parent=ptt.PlayerGui end end scr.Touched:connect(onTouch)
|
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 02:53 PM |
| ^ Thank you so much!! It works :,) |
|
|
| Report Abuse |
|
|