Answered by
5 years ago Edited 5 years ago
03 | local NPCUI = script.Parent |
04 | local MainFrame = NPCUI.MainFrame |
05 | local Body = MainFrame.Body |
06 | local MainFrame 2 = MainFrame.MainFrame 2 |
11 | MainFrame 2. Exit.MouseButton 1 Click:Connect( function () |
12 | MainFrame.Body:Destroy() |
13 | MainFrame.MainFrame 2 :Destroy() |
14 | MainFrame:TweenSize(UDim 2. new( 0.016 , 0 , 0.63 , "Out" , "Quad" , 0.5 )) |
16 | game.ReplicatedStorage.DestroyGui:FireServer(NPCUI) |
the code below will be a server script
1 | game.ReplicatedStorage.DestroyGui.OnServerEvent:Connect( function (player,ui) |
2 | if ui.Parent = player.PlayerGui then |
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
02 | script.Parent.UpperTorso.ClickDetector.MouseClick:Connect( function (plr) |
05 | if not plr.PlayerGui:FindFirstChild( "NPC" ) then |
06 | local clone = script.Parent.NPC:Clone() |
07 | clone.Parent = plr.PlayerGui |
08 | clone.MainFrame:TweenSize(UDim 2. new( 0.649 , 0 , 0.63 , 0 , "Out" , "Quad" , 0.5 )) |
10 | clone.MainFrame.Body.Visible = true |
11 | clone.MainFrame.MainFrame 2. Visible = true |
12 | wait(amount of time before the player can do it again here) |
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