Need help with second-time speaking with NPCs

working on a RPG game with some friends that has a pretty heavy focus on speaking to NPCs. It’s going well but i’m not entirely sure what to do to make it so that when you speak to a npc for a second time they say something else. Sorry if it’s something really easy and im not thinking of it.
(relatively new to scripting properly)
It’s dialogue with a UI, and uses a proximity prompt if that changes how you think.

You can use a variable that keep track of how many times they talked to the same NPC :slight_smile:

im not sure what i’ve done wrong, and no error messages are popping up, but no text is showing up under this code

local TextLabel = script.Parent:WaitForChild(“Frame”):WaitForChild(“TextLabel”)
local counter = 0

script.Value.Value.Enabled = false

function SoundEffect()
local Sound = Instance.new(“Sound”, workspace)
Sound.Name = “TextSound”
Sound.SoundId = “http://www.roblox.com/asset/?id=0
Sound.PlaybackSpeed = 1
Sound.Volume = 1
Sound:Play()
coroutine.resume(coroutine.create(function()
wait(1)
Sound:Destroy()
end))
end

function setText(word)
local Text = word
for i = 1, #Text do
TextLabel.Text = string.sub(Text, 1, i)
SoundEffect()
wait(0.04)
end
end

function onPlayerInteract()
print(“clicked”)
counter = counter + 1
if counter == 1 then
setText(“first”)
elseif counter == 2 then
setText(“second”)
elseif counter == 3 then
setText(“third”)
else
setText(“defaulttext”)
end
end

script.Value.Value.Enabled = true

local proximityPrompt = script.Parent:WaitForChild(“ProximityPrompt”)

proximityPrompt.Action:Connect(onPlayerInteract)

what was your original working code before implementing the counter variable?

try printing the “first”, "second, “third” and “defaulttext” instead of setting it to the TextLabel so maybe we can see the problem

local TextLabel = script.Parent:WaitForChild(“Frame”):WaitForChild(“TextLabel”)
script.Value.Value.Enabled = false

function SoundEffect()
local Sound = Instance.new(“Sound”,workspace)
Sound.Name = “TextSound”
Sound.SoundId = “http://www.roblox.com/asset/?id=0
Sound.PlaybackSpeed = 1
Sound.Volume = 1
Sound:Play()
coroutine.resume(coroutine.create(function()
wait(1)
Sound:Destroy()
end))
end

function setText(word)
local Text = word
for i = 1, #Text do
TextLabel.Text = string.sub(Text, 1, i)
SoundEffect()
wait(0.04)
end
end

setText(“text”)
wait(1)

script.Value.Value.Enabled = true
script.Destroyer:FireServer()

^ the code before adding the counter variable.
I’ll try doing it with printing, one second

One thing to point out is that the event to know when the player has triggered the prompt is not proximityPrompt.Action, it is proximityPrompt.Triggered. Besides that, the code you sent works fine on my end.

it doesnt do the multiple texts for me, I’ll try the proper proximity prompt term and see how it works. Thanks.