From 2ec90a2630a3b4ff69c9b6e03b786917e574f26d Mon Sep 17 00:00:00 2001 From: Thomas G <62822072+Thomasluigi07@users.noreply.github.com> Date: Fri, 16 Sep 2022 03:40:04 +1000 Subject: [PATCH] Update 6 --- public/asset/6 | 116 +++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 48 deletions(-) diff --git a/public/asset/6 b/public/asset/6 index 9d902b0..9564830 100644 --- a/public/asset/6 +++ b/public/asset/6 @@ -1,4 +1,17 @@ %6% +function waitForProperty(instance, name) + while not instance[name] do + instance.Changed:wait() + end +end + +function waitForChild(instance, name) + while not instance:FindFirstChild(name) do + instance.ChildAdded:wait() + end +end + + local mainFrame local choices = {} local lastChoice @@ -23,6 +36,15 @@ local reenableDialogScript local dialogMap = {} local dialogConnections = {} +local gui = nil +waitForChild(game,"CoreGui") +waitForChild(game.CoreGui,"RobloxGui") +if game.CoreGui.RobloxGui:FindFirstChild("ControlFrame") then + gui = game.CoreGui.RobloxGui.ControlFrame +else + gui = game.CoreGui.RobloxGui +end + function currentTone() if currentConversationDialog then return currentConversationDialog.Tone @@ -404,7 +426,7 @@ end function checkForLeaveArea() while currentConversationDialog do - if player:DistanceFromCharacter(currentConversationDialog.Parent.Position) >= currentConversationDialog.ConversationDistance then + if currentConversationDialog.Parent and (player:DistanceFromCharacter(currentConversationDialog.Parent.Position) >= currentConversationDialog.ConversationDistance) then wanderDialog() end wait(1) @@ -416,7 +438,7 @@ function startDialog(dialog) if player:DistanceFromCharacter(dialog.Parent.Position) >= dialog.ConversationDistance then showMessage(tooFarAwayMessage, tooFarAwaySize) return - end + end for dialog, gui in pairs(dialogMap) do if dialog and gui then @@ -431,19 +453,6 @@ function startDialog(dialog) end end - -function waitForProperty(instance, name) - while not instance[name] do - instance.Changed:wait() - end -end - -function waitForChild(instance, name) - while not instance:FindFirstChild(name) do - instance.ChildAdded:wait() - end -end - function removeDialog(dialog) if dialogMap[dialog] then dialogMap[dialog]:Remove() @@ -456,43 +465,57 @@ function removeDialog(dialog) end function addDialog(dialog) - if dialog.Parent and dialog.Parent:IsA("BasePart") then - local chatGui = chatNotificationGui:clone() - chatGui.Enabled = not dialog.InUse - chatGui.Adornee = dialog.Parent - chatGui.RobloxLocked = true - chatGui.Parent = game.CoreGui - chatGui.Image.Button.MouseButton1Click:connect(function() startDialog(dialog) end) - setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) - - dialogMap[dialog] = chatGui + if dialog.Parent then + if dialog.Parent:IsA("BasePart") then + local chatGui = chatNotificationGui:clone() + chatGui.Enabled = not dialog.InUse + chatGui.Adornee = dialog.Parent + chatGui.RobloxLocked = true + chatGui.Parent = game.CoreGui + chatGui.Image.Button.MouseButton1Click:connect(function() startDialog(dialog) end) + setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) + + dialogMap[dialog] = chatGui - dialogConnections[dialog] = dialog.Changed:connect(function(prop) - if prop == "Parent" and dialog.Parent then - --This handles the reparenting case, seperate from removal case - removeDialog(dialog) - addDialog(dialog) - elseif prop == "InUse" then - chatGui.Enabled = not currentConversationDialog and not dialog.InUse - if dialog == currentConversationDialog then + dialogConnections[dialog] = dialog.Changed:connect(function(prop) + if prop == "Parent" and dialog.Parent then + --This handles the reparenting case, seperate from removal case + removeDialog(dialog) + addDialog(dialog) + elseif prop == "InUse" then + chatGui.Enabled = not currentConversationDialog and not dialog.InUse + if dialog == currentConversationDialog then timeoutDialog() - end - elseif prop == "Tone" or prop == "Purpose" then - setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) - end - end) + end + elseif prop == "Tone" or prop == "Purpose" then + setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) + end + end) + else -- still need to listen to parent changes even if current parent is not a BasePart + dialogConnections[dialog] = dialog.Changed:connect(function(prop) + if prop == "Parent" and dialog.Parent then + --This handles the reparenting case, seperate from removal case + removeDialog(dialog) + addDialog(dialog) + end + end) + end end end function fetchScripts() - --print("InsertService") local model = game:GetService("InsertService"):LoadAsset(39226062) - --print(model) - while model == "No assetUrl set" do - --print("Trying again to fetch Scripts") + if type(model) == "string" then -- load failed, lets try again + wait(0.1) model = game:GetService("InsertService"):LoadAsset(39226062) end + if type(model) == "string" then -- not going to work, lets bail + return + end + + waitForChild(model,"TimeoutScript") timeoutScript = model.TimeoutScript + waitForChild(model,"ReenableDialogScript") reenableDialogScript = model.ReenableDialogScript end @@ -506,17 +529,14 @@ function onLoad() --print("Creating Guis") createChatNotificationGui() - - --print("Waiting for RobloxGui") - waitForChild(game.CoreGui, "RobloxGui") --print("Creating MessageDialog") createMessageDialog() messageDialog.RobloxLocked = true - messageDialog.Parent = game.CoreGui.RobloxGui + messageDialog.Parent = gui --print("Waiting for BottomLeftControl") - waitForChild(game.CoreGui.RobloxGui, "BottomLeftControl") + waitForChild(gui, "BottomLeftControl") --print("Initializing Frame") local frame = Instance.new("Frame") @@ -525,7 +545,7 @@ function onLoad() frame.Size = UDim2.new(0,0,0,0) frame.BackgroundTransparency = 1 frame.RobloxLocked = true - frame.Parent = game.CoreGui.RobloxGui.BottomLeftControl + frame.Parent = gui.BottomLeftControl initialize(frame) --print("Adding Dialogs")