function positionDialogue()
local currentNPCRoot = ebutton.Parent
local currentPosition = currentNPCRoot
print(currentPosition.Position)
if currentPosition.Position == Vector3.new(-15.55, 2.7, 44.57) then
dialogue = require(script:WaitForChild("DialogueOne"))
end
end
I wouldn’t recommend getting the dialogue from checking the position, as it could be unreliable and change. In this instance, what I’d do is I’d give the NPC a value. Each value represents a point. You change the value when you change the position. Then, instead of checking the position, you check the value.
It appears that it can’t find the dialogue variable.
If you add the dialogue variable at the top, it should scope and find it instead of erroring it.
local player = game.Players.LocalPlayer
local npcs = workspace.NPCs:GetChildren()
local ebutton = game.ReplicatedStorage.EButton
local uis = game:GetService("UserInputService")
local dialogueUI = player.PlayerGui:WaitForChild("DialogueUI")
local bg = dialogueUI.Background
local currentPage = 1
local currentNPC = ""
local dialogue
Nothing seemed to change, the GUI still doesn’t enable
This is what is printing in output:
Summary
This is area of code where the printing is coming from
print("Working up till typing")
positionDialogue()
print("What")
print(tostring(dialogue)) -- prints the value of the variable
if dialogue then
typing(dialogue[currentNPC]["Page1"][1], dialogue[currentNPC]["Page1"][2])
end
This means that calling positionDialogue is printing?
This is what I’d do,
If other scripts are going to access the point, I’d make an IntValue within the NPC
When you move an NPC to a point, change the IntValue to a unique value
Now, whenever you want to check the position, simply check if its the unique value.
Hope it helps!
Thanks to everyone help I was able to figure out the best way for me to track the position of the HumanoidRootPart.
I made a separate script to print the exact position of the part over 20 seconds
Summary
local Feugazi = workspace.NPCs.Feugazi
local Root = Feugazi.HumanoidRootPart
local Postion = Root.Position
for count = 1,20 do
wait (1)
print(Postion)
end
print(Postion)
I then was able to place the position into this function. This allowed the script to choose the correct module script to load the Dialogue into the GUI.
Summary
function positionDialogue()
local currentNPCRoot = ebutton.Parent
local currentPosition = currentNPCRoot
if currentPosition.Position == Vector3.new( -15.5499992, 2.69999981, 44.5700035) then
dialogue = require(script:WaitForChild("DialogueOne"))
end
end
(The if/then statement can be copy and pasted as many times as need within the function so that many different Dialogues can be used.)
I then just called the function within the Dialogue version of the script, and loaded the correct Dialogue set into the players GUI when it’s needed
Summary
positionDialogue() -- PRINTS THE POSITION OF THE NPC
if dialogue then
typing(dialogue[currentNPC]["Page1"][1], dialogue[currentNPC]["Page1"][2])
end