Trying to handle dialog text for multiple NPCs

so i have different NPCs for different shops. i want each NPC to have different dialog text.


because this is my custom proximity prompt script, i was thinking about sending the CharacterAttribute value which holds the NPC’s name to another local script in my dialog UI so i can organize stuff better and handle the text from there. unfortunately i’ve never handled multiple dialog UI’s for different NPCs so i’m kinda stuck rn so i appreciate any help at all ty. :slight_smile:

custom proximity prompt script (stored in starterplayerscripts)

local function OnTriggered(prompt, playerWhoTriggered)
	if debounce[playerWhoTriggered] then return end
	debounce[playerWhoTriggered] = true
	local object = prompt.Parent
	local CharacterAttribute = object:GetAttribute("Character")
	
	print("you're interacting with "..CharacterAttribute.."!")
end

local function ConnectPromptEvent(event, callback)
	event:Connect(function(prompt, ...)
		if prompt.Style == Enum.ProximityPromptStyle.Default then return end
		callback(prompt, ...)
	end)
end

ConnectPromptEvent(ProximityPromptService.PromptTriggered, function(prompt, playerWhoTriggered)
	OnTriggered(prompt, playerWhoTriggered)
end)

i’m trying to hook the Dialog text up to the text in my CharacterData module which is my end goal.

local CharacterData= {
	["Dodgy Darren"] = {
		ObjectText = "Dodgy Darren",
		ActionText = "Talk",
		ObjectTextColor = Color3.fromRGB(255, 0, 4),
		ActionTextColor = Color3.fromRGB(255, 249, 65),
		
		Options = {
			"[Who are you?]",
			"[Why is  your name Dodgy Darren?]",
			"[Why are you here?]",
			"[I think I'll go now...]"
		}
	},
	
	["Trading Tadhg"] = {
		ObjectText = "Trading Tadhg",
		ActionText = "Talk",
		ObjectTextColor = Color3.fromRGB(255, 255, 255),
		ActionTextColor = Color3.fromRGB(255, 249, 65),

		Options = {
			"[I want to sell my inventory]",
			"[I want to sell this]",
			"[How much is this worth?]",
			"[Nevermind]"
		}
	},
return CharacterData

what are you confused about?

i would make a pre-made billboard gui and “sample” question, when the proximity prompt triggers, clone the billboardgui, and for each question clone the sample and set the question # and the question text.

modulescripts? (or bindable events, but these are considered bad practice)

your also never setting debounce to false again

you also dont need to make your characters name blank, just set the humanoids DisplayDistanceType to None

1 Like

bindable events are considered bad practice?
can you explain why? ( or Link it )

bindable events arent inheritly considered bad practice, but they aren’t the best practice; there are a couple of topics about why they arent “good” but ill make a small summary of what i know:

  • data has to be serialized / deserialized, not all data can do this
  • bindables were made before modulescripts, modulescripts are now the best for making reusable code
2 Likes

But are they slower than module scripts? Yes

I saw someone using it to expose the functions of a script to the explorer and thought that this was a good idea, especially if another scripter tried to look at the script name and didn’t know what to expect.

Wait… do bindable events have the same limit as remote events? ( you can’t pass instances )
If yes, that’s a good reason to not use them.

nvm… you can pass instances but not as an index of a table

Thanks Snow.


To OP.

I didn’t want to do this, but here we go. I’m not a fan of making a tables with both dictionary and numerical values.

-- a few ways to handle what happens when you pick a message.
Options = {
	{
		message = "[Who are you?]"
		 -- do it in the same module... not fun when you have a lot of NPCs/Long functions
		activate = function(player: Player)
			player.Cash.Value += 5000,
		end
	},Character
	{
		message = "[Why is  your name Dodgy Darren?]"
		activate = SomeOtherModule.SetNpcMessage("No one were ever able to catch and hug me so they called me Dodgy while laughing")
	},
		message = "[I think I'll go now...]"
		-- redirect activate calls to another function in some other module for better organization. ( my favorite one )
		activate = SomeOtherModule.DestroyPlayer,
	}
}

We don’t know what you’re asking/having trouble with, so we both ( kinda ) assumed the problem.

thank you all for all the help, i really appreciate it. :slight_smile:

apologies if i wasn’t clear but at the end of it all i figured it out eventually. :exclamation:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.