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

How to detect who's using a dialog?

Asked by 9 years ago

Hey guys, I know you can use DialogChoiceSelected to get who's speaking to someone when they select a DialogChoice, but I want to know how to detect who's using a dialog (AKA: who triggered the InUse property to become true.)

I am trying to make an NPC that stops and keeps looking at the player who's talking to them until they either walk away or when the conversation ends, then goes back to what they were doing.

Here is my current script so far:

local region = require(game.ServerScriptService:WaitForChild("RegionScript"))
local paths = game.Lighting.Paths:GetChildren()
local npc = script.Parent
local hum = npc:WaitForChild("Humanoid")
local torso = npc:WaitForChild("Torso")
local head = npc:WaitForChild("Head")
local dialog = head:WaitForChild("ChatDialog")

while dialog.InUse ~= true do --When the NPC isn't being talked to.
    local rand = math.random(1,#paths)
    local randLoc = region:RandomiseLocation(paths[rand])
    print(randLoc.X, randLoc.Y, randLoc.Z)
    hum:MoveTo(randLoc)
    local speed = hum.Running:wait()
    if speed ~= 0 then repeat speed = hum.Running:wait() until speed == 0 end
    wait(2)
end

while dialog.InUse == true do --When the NPC is being talked to.
    hum.WalkSpeed = 0
    --Need to do something here to find the player that's talking to the NPC.
    torso.CFrame = CFrame.new(torso.Position, Vector3.new(Mouse.Hit.p.x, torso.Position.Y, Mouse.Hit.p.z)) --Stuck here as I need to find the player. Ignore Mouse.Hit as I was trying to find out how to turn a character towards someone.
end

Any help is appreciated, thanks!

0
There's no way to get the player from the initial dialog activation.. unless you like put the npc in CurrentCamera and used localplayer or something but idk if that would even work Goulstem 8144 — 9y

1 answer

Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

This is just theory.

What you want to do is: Have a Boolean value that makes the NPC only do their action while it is true, then: Make a function that fires when a player goes within x studs of the NPC, make the value false to stop them from doing their NPC stuff. Input BodyGyro in the NPC's torso to make them face the player.

Then when then conversation ends or they move away from the player (more than x studs), which can be achieved by having a function run every time the player's torso's position moves, and then checking if they are further than x studs (< x studs), you would then remove the BodyGyro and make the boolean true again so they carry on NPC stuff

This doesn't answer your code, but I think it helps you concerning you second paragraph.

I am trying to make an NPC that stops and keeps looking at the player who's talking to them until they either walk away or when the conversation ends, then goes back to what they were doing.

Ad

Answer this question