Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

I'm trying to make you not ABLE to spam click an NPC to open a UI. Help?

Asked by
Aqu_ia 39
5 years ago
Edited 5 years ago

Here is my script to clone the ui. It is SUPPOSED to check whether or not the UI is in PlayerGui and will clone it if it is not.

01script.Parent.UpperTorso.ClickDetector.MouseClick:Connect(function(plr)
02    if not plr.PlayerGui:FindFirstChild("NPC") then
03    local clone = script.Parent.NPC:Clone() ----{0.175, 0},{0.185, 0}
04    clone.Parent = plr.PlayerGui
05    clone.MainFrame:TweenSize(UDim2.new(0.649,0,0.63,0, "Out", "Quad", 0.5))
06    wait(1)
07    clone.MainFrame.Body.Visible = true
08    clone.MainFrame.MainFrame2.Visible = true
09        end
10    end)

GUI Script:

01--// Variables
02 
03local NPCUI = script.Parent
04local MainFrame = NPCUI.MainFrame
05local Body = MainFrame.Body
06local MainFrame2 = MainFrame.MainFrame2
07 
08 
09--// Functions
10 
11MainFrame2.Exit.MouseButton1Click:Connect(function()
12    MainFrame.Body:Destroy()
13    MainFrame.MainFrame2:Destroy()
14    MainFrame:TweenSize(UDim2.new(0.016,0,0.63,"Out","Quad",0.5))--{0.649, 0},{0.63, 0}
15    wait(1)
View all 22 lines...

I need some help, please. If this is not enough info, you can comment down in the question. Thank you very much.

0
What happens when you test this script, and how does it differ from what you want to happen? gskw 1046 — 5y
0
The first time I click on the NPC it works, however, when I click it the second time, the GUI doesn't appear. Aqu_ia 39 — 5y
0
this is because you are not removing the gui from the player gui Gameplayer365247v2 1055 — 5y
0
If you want the NPC's UI to appear again only after you've closed it first, you should use :Destroy() on plr.PlayerGui.NPC when the UI is closed. In that case the culprit might not be the script you've posted. gskw 1046 — 5y
View all comments (6 more)
1
I see. I have just edited the question aka the script from above to help you out. Aqu_ia 39 — 5y
0
Thanks! Could you also tell us if the ClickDetector script is a LocalScript or a regular Script, and the same about the GUI script? gskw 1046 — 5y
0
no this is actually not needed since it is a clickdetector, the clickdetector gets a signal when its clicked on which player clicked it and can then access their playergui and other things Gameplayer365247v2 1055 — 5y
0
My script for the click detector to work is just on a regular script, not a local script. For the GUI, it is a local script. Aqu_ia 39 — 5y
0
good thats how it should be but i just realised why it wont show up and i will put it down as an answer Gameplayer365247v2 1055 — 5y
0
Nevermind. Aqu_ia 39 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago
01--// Variables
02 
03local NPCUI = script.Parent
04local MainFrame = NPCUI.MainFrame
05local Body = MainFrame.Body
06local MainFrame2 = MainFrame.MainFrame2
07 
08 
09--// Functions
10 
11MainFrame2.Exit.MouseButton1Click:Connect(function()
12    MainFrame.Body:Destroy()
13    MainFrame.MainFrame2:Destroy()
14    MainFrame:TweenSize(UDim2.new(0.016,0,0.63,"Out","Quad",0.5))--{0.649, 0},{0.63, 0}
15    wait(1)
View all 22 lines...

the code below will be a server script

1game.ReplicatedStorage.DestroyGui.OnServerEvent:Connect(function(player,ui)
2if ui.Parent = player.PlayerGui then
3ui:Destroy()
4end
5end)

the reason we need a server script for this and a remote event is that in your local script you are just deleting the ui localy not globaly this means the server will still see it as the gui is in your player gui and since the clickdetector script is a server script it will find that gui and therefore not give you a new gui

the clickdetector script edited below

01allowed = true
02script.Parent.UpperTorso.ClickDetector.MouseClick:Connect(function(plr)
03    if allowed then
04    allowed = false
05    if not plr.PlayerGui:FindFirstChild("NPC") then
06    local clone = script.Parent.NPC:Clone() ----{0.175, 0},{0.185, 0}
07    clone.Parent = plr.PlayerGui
08    clone.MainFrame:TweenSize(UDim2.new(0.649,0,0.63,0, "Out", "Quad", 0.5))
09    wait(1)
10    clone.MainFrame.Body.Visible = true
11    clone.MainFrame.MainFrame2.Visible = true
12    wait(amount of time before the player can do it again here)
13    allowed = true
14          end
15        end
16    end)

by doing this we are setting a block that checks if something is true or not and if it is then the player can get the gui. you can use anything you want instead of allowed as long as it = true or = false and if you do = false then do the opposite way of how i did it and in the if statement do if not allowed then

0
Okay. I see now. I'll test it out and see if it works. Aqu_ia 39 — 5y
0
It works, but that leads me back to my first question which is that I'm trying to make it so the click detector isn't spammable which allows the GUI to clone itself when the click detector is clicked MULTIPLE times. Aqu_ia 39 — 5y
0
FilteringEnabled can sometimes have unexpected consequences. I would personally prefer to not clone the GUI on the server at all, and instead fire a RemoteEvent to the client to create the GUI. gskw 1046 — 5y
0
no this is not very good to do, my answer is better Gameplayer365247v2 1055 — 5y
View all comments (4 more)
0
Additionally, you need to put a check in OnServerEvent to see if `ui` is actually a GuiObject and if it's a descendant of the Player. Otherwise the RemoteEvent effectively functions as an FE bypass for deleting anything in the game. gskw 1046 — 5y
1
Here's my problem. It is spammable although I already put an "if not" statement to prevent it from being spammed. | Here's an example: https://gyazo.com/5601d7cc42f7fdead76d290377f86791 Aqu_ia 39 — 5y
0
yes gskw that is correct and i had forgotten about that but i edited it a little bit and here is the final outcome Gameplayer365247v2 1055 — 5y
0
Okay, thanks for the help. It works and it doesn't spam. Thanks again! Aqu_ia 39 — 5y
Ad

Answer this question