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.
script.Parent.UpperTorso.ClickDetector.MouseClick:Connect(function(plr) if not plr.PlayerGui:FindFirstChild("NPC") then local clone = script.Parent.NPC:Clone() ----{0.175, 0},{0.185, 0} clone.Parent = plr.PlayerGui clone.MainFrame:TweenSize(UDim2.new(0.649,0,0.63,0, "Out", "Quad", 0.5)) wait(1) clone.MainFrame.Body.Visible = true clone.MainFrame.MainFrame2.Visible = true end end)
GUI Script:
--// Variables local NPCUI = script.Parent local MainFrame = NPCUI.MainFrame local Body = MainFrame.Body local MainFrame2 = MainFrame.MainFrame2 --// Functions MainFrame2.Exit.MouseButton1Click:Connect(function() MainFrame.Body:Destroy() MainFrame.MainFrame2:Destroy() MainFrame:TweenSize(UDim2.new(0.016,0,0.63,"Out","Quad",0.5))--{0.649, 0},{0.63, 0} wait(1) NPCUI:Destroy() end) --// Made by Aquawoman
I need some help, please. If this is not enough info, you can comment down in the question. Thank you very much.
--// Variables local NPCUI = script.Parent local MainFrame = NPCUI.MainFrame local Body = MainFrame.Body local MainFrame2 = MainFrame.MainFrame2 --// Functions MainFrame2.Exit.MouseButton1Click:Connect(function() MainFrame.Body:Destroy() MainFrame.MainFrame2:Destroy() MainFrame:TweenSize(UDim2.new(0.016,0,0.63,"Out","Quad",0.5))--{0.649, 0},{0.63, 0} wait(1) game.ReplicatedStorage.DestroyGui:FireServer(NPCUI)--make a remote event and call it DestroyGui end) --// Made by Aquawoman
the code below will be a server script
game.ReplicatedStorage.DestroyGui.OnServerEvent:Connect(function(player,ui) if ui.Parent = player.PlayerGui then ui:Destroy() end end)
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
allowed = true script.Parent.UpperTorso.ClickDetector.MouseClick:Connect(function(plr) if allowed then allowed = false if not plr.PlayerGui:FindFirstChild("NPC") then local clone = script.Parent.NPC:Clone() ----{0.175, 0},{0.185, 0} clone.Parent = plr.PlayerGui clone.MainFrame:TweenSize(UDim2.new(0.649,0,0.63,0, "Out", "Quad", 0.5)) wait(1) clone.MainFrame.Body.Visible = true clone.MainFrame.MainFrame2.Visible = true wait(amount of time before the player can do it again here) allowed = true end end 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