Script:
script.Parent.ClickDetector.MouseClick:Connect(function(player) -- Detect player clicked head.
if player.PlayerGui.Chats:FindFirstChildOfClass("ScreenGui") == nil then --Here's the problem.
print("giving") -- print when the Gui is succesfully given.
local GUI = game.Lighting.SpyChatThing:Clone() -- Clone the Gui
GUI.Parent = player.PlayerGui.Chats Put Gui in player's Gui
GUI.StartTalking:FireClient(player) -- Ignore this
else
print("Already has the Gui") -- print if the Gui is already in the player's Gui
end
end)
So, the script checks if the Player is already chatting with the NPC, by seeing if there is a "NPCChatGui". So, at first, it works, but the second time you clik the NPC 's Head, the script thinks the Gui is still active, but it's not.
Here's the script that closes the Gui
local Button = script.Parent:FindFirstChild("Answer")
Button.Activated:Connect(function()
script.Parent:Destroy()
end)

7 comments
Do you destroy the GUI anywhere? If so, can you show that script?
This is the script inside the Gui, wich detects when a player clicks certain button. Then destroy's the Gui
This is the script inside the Gui, wich detects when a player clicks certain button. Then destroy's the Gui
sorry, acidentally sent the message two times, but i edited the post now
When you are cloning the GUI into the player gui, you are doing that on server, it is generally a bad practice however if you do so, you need to destroy it on the server too, everything done on the client CANNOT be seen on the server so you destroyed it on the client, not on the server, try using RemoteEvents for that or just switching to local scripts.
ohhhh
yesss! thank you!