So, I want it that when the player clicks on the question mark above the NPC’s head, I want it to play a noise immediately. This is why I can’t use DialogChoiceSelected. Does anyone know how I’d go about doing this?
I think you can use Dialog’s .InUse property along with a GetPropertyChanged signal as i think it will fire as soon as the ? is clicked
dialog:GetPropertyChangedSignal('InUse'):Connect(function()
if not dialog.InUse then return end
--play sound
end)
3 Likes
One issue with this is if the dialog is being interacted with by two or more players, the InUse property will remain as true, to circumvent this you could do the following.
local run = game:GetService("RunService")
local players = game:GetService("Players")
local dialog = script.Parent --Example dialog.
local sound = script.Sound --Example sound.
local loggedPlayers = {}
local function onHeartbeat()
local dialogPlayers = dialog:GetCurrentPlayers()
for _, dialogPlayer in ipairs(dialogPlayers) do
if table.find(loggedPlayers, dialogPlayer) then continue end
table.insert(loggedPlayers, dialogPlayer)
sound:Play()
end
end
local function onPlayerRemoving(player)
loggedPlayers[player] = nil
end
run.Heartbeat:Connect(onHeartbeat)
players.PlayerRemoving:Connect(onPlayerRemoving)
Additionally, you can implement a system which removes a player from the “loggedPlayers” table when that player closes the dialog, such that if they were to open the dialog again the sound would play again.
1 Like