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

Im making a chat NPC im having a problem, FindFirstChild() only checks once. Help?

Asked by
ZIRFAL3 17
3 years ago
Edited 3 years ago

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)
0
Do you destroy the GUI anywhere? If so, can you show that script? imKirda 4491 — 3y
0
This is the script inside the Gui, wich detects when a player clicks certain button. Then destroy's the Gui ZIRFAL3 17 — 3y
0
This is the script inside the Gui, wich detects when a player clicks certain button. Then destroy's the Gui ZIRFAL3 17 — 3y
0
sorry, acidentally sent the message two times, but i edited the post now ZIRFAL3 17 — 3y
View all comments (3 more)
0
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. imKirda 4491 — 3y
0
ohhhh ZIRFAL3 17 — 3y
0
yesss! thank you! ZIRFAL3 17 — 3y

Answer this question