|
| 23 Jan 2012 06:07 PM |
| I hear that this is a common problem. What does it mean? What possible problems are there? How can I fix it? |
|
|
| Report Abuse |
|
|
xvgigakid
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 4407 |
|
|
| 23 Jan 2012 06:09 PM |
It means that an error in your script only allows it to run locally. This is either because it is running on server time and it was not giving the server time to load. Post your script and ill be able to fix it. |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2012 06:13 PM |
It's a little long. I guess I can let you look at it.
LocalPlayer = game:GetService("Players").LocalPlayer
print("DialogueReceiver initiated") Screen = script.Parent
function GetClosest(p1, p2) if (LocalPlayer.Character.Head.Position - p1.Position).magnitude < (LocalPlayer.Character.Head.Position - p2.Position).magnitude then return p1 else return p2 end end
function GetParts(objects) local newTable = {} for _, v in pairs(objects:GetChildren()) do if v:IsA("BasePart") and v:findFirstChild("RandomDialogue") then table.insert(newTable, v) end for _, vv in pairs(GetParts(v)) do table.insert(newTable, vv) end end
return newTable end
function GetPartsInRadius(parts, radius) local newParts = {} for _, v in pairs(parts) do if LocalPlayer:DistanceFromCharacter(v.Position) < radius then table.insert(newParts, v) end end return newParts end
DialogueParts = {} ActiveDialogue = nil
function SelectChoice(choice) print("DialogueReceiver: SelectChoice(" .. choice.Name .. ") initiated") ClearDialogue() Screen.DialoguePath.Value = choice Screen.DialogueText.Text = choice.Dialog.Value local i = -1 if choice:IsA("StringValue") then for _, v in pairs(choice.Dialog:GetChildren()) do i = i + 1 Screen["DialogueChoice" .. tostring(i)].Text = v.Value end end end
function GetResponse() print("DialogueReceiver: GetResponse() initiated") repeat print("DialogueReceiver: GetResponse() looping") Screen.ReturnDialogue.Value = false repeat wait() until Screen.ReturnDialogue.Value
local SelectedDialogue = Screen.SelectedDialogue.Value if SelectedDialogue.inUse.Value then print("DialogueReceiver: GetResponse() grabbed response: " .. SelectedDialogue.Text) local previousPath = Screen.DialoguePath.Value local response = previousPath.Dialog:findFirstChild(SelectedDialogue.Name) Screen.ReturnDialogue.Value = false if response then if response:findFirstChild("Dialog") then return response end end return nil end until not Screen.inConversation.Value end
function ClearDialogue() for i = 0, 9 do Screen["DialogueChoice" .. tostring(i)].Text = "" end end
ClearDialogue()
RandomDialogue = coroutine.create(function() print("RandomDialogue routine initiated")
Screen.Key.Changed:connect(function(Property) if Screen.Key.Value == "e" and ActiveDialogue and not Screen.inConversation.Value then if ActiveDialogue:findFirstChild("InitialPrompt") then print("DialogueReceiver: Starting conversation") Screen.inConversation.Value = true end end end)
while wait() do DialogueParts = GetPartsInRadius(GetParts(Workspace), 10) if #DialogueParts > 1 then for _ = 1, #DialogueParts - 1 do DialogueParts[1] = GetClosest(DialogueParts[1], DialogueParts[2]) table.remove(DialogueParts, 2) end end ActiveDialogue = DialogueParts[1]
if ActiveDialogue and not Screen.inConversation.Value then Screen.RandomDialogue.Text = ActiveDialogue.RandomDialogue.Value Screen.RandomDialogue.Visible = true else Screen.RandomDialogue.Visible = false end end end)
coroutine.resume(RandomDialogue)
Screen.inConversation.Changed:connect(function(Property)
script.StopConversation.Changed:connect(function(Property) if script.StopConversation.Value then print("DialogueReceiver: Stopping conversation") script.StopConversation.Value = false Screen.inConversation.Value = false end end)
if Screen.inConversation.Value then
print("DialogueReceiver: Conversation initiated") coroutine.yield(RandomDialogue)
ClearDialogue()
listenResponse = Screen.DialoguePath.Changed:connect(function(Property) local dpath = Screen.DialoguePath.Value print("DialogueReceiver: DialoguePath changed to " .. dpath.Name .. ", updating dialogue") local response = GetResponse() print("DialogueReceiver: Player responded") if response then SelectChoice(response) else script.StopConversation.Value = true end Screen.ReturnDialogue.Value = false end)
SelectChoice(ActiveDialogue.InitialPrompt) else listenResponse:disconnect() Screen.DialoguePath.Value = nil Screen.ReturnDialogue.Value = false end
end)
coroutine.resume(coroutine.create(function() while wait() do for i = 0, 9 do local iteration = Screen["DialogueChoice" .. tostring(i)] if iteration.Text == "" then iteration.inUse.Value = false else iteration.inUse.Value = true end end end end))
coroutine.resume(coroutine.create(function() while wait() do pcall(function() if Screen.inConversation.Value and (LocalPlayer.Character.Head.Position - ActiveDialogue.Position).magnitude >= 10 then script.StopConversation.Value = true end end) end end)) |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2012 06:16 PM |
| Oh, I forgot to say that this is a local script. |
|
|
| Report Abuse |
|
|
Grove537
|
  |
| Joined: 05 Feb 2010 |
| Total Posts: 3478 |
|
|
| 23 Jan 2012 06:17 PM |
| Add wait(3) to the very top, always works for me :3 |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2012 06:19 PM |
| Well, I understand what you're doing. But this approach to the problem bothers me. What if the script needs to be running in those first three seconds of gameplay? I want a more fail-safe solution. |
|
|
| Report Abuse |
|
|
xvgigakid
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 4407 |
|
|
| 23 Jan 2012 06:20 PM |
Grove is right you need to give it some time for the player to load everything. But wait(0.1) is a better idea. It only take about 1-3 frames to load the objects. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
xvgigakid
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 4407 |
|
| |
|