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

Can someone help me with my NPC talking system?

Asked by 3 years ago
Edited 3 years ago

Hello all you Scripting Geniuses,

I am running a Server-Side Script, to make an NPC talk.

Please note, I am not trying to make a dialogue, where the player can respond, just where the NPC says something, and that is it.

My Script runs two different lines of code, in order to make the NPC talk different sentences.

The first line works perfectly, and the NPC says the required sentence once. I have copied it out below.

local chatService = game:GetService("Chat")

chatService:Chat(game.Workspace.NPC1.Head, "Can I please get a ticket?", "Green")

The second section seems to execute twice, although the event is only being fired once. What is interesting, is that it appears from two different places, one where it would be expected to show (the NPC head), and the other right of that.

Again, please see the code I am using below.

ticketGiven.OnServerEvent:Connect(function()
    chatService:Chat(game.Workspace.NPC1.Head, "Thanks!", "Red")
end)

I also have a remote event set up, used in the second snippet, with a local script connected to a Surface Gui / Text Button, which fires the remote event on mouse click.

The local script is not the problem, from what I can see.

EDIT -- {But, I have attached it anyway, on request.}

local replicatedStorage = game:GetService("ReplicatedStorage")
local valuesFolder = replicatedStorage:FindFirstChild("Values")
local customerRequesting = valuesFolder:FindFirstChild("CustomerRequesting")
local eventFolder = replicatedStorage:FindFirstChild("Remote Events")
local ticketGiven = eventFolder:FindFirstChild("TicketGiven")

local Button = script.Parent.Button

Button.MouseButton1Click:Connect(function()
    if customerRequesting.Value == true then
        ticketGiven:FireServer()
    else
        print("No customer requested a ticket.")
    end
end)

If anyone could shine some light on why the second line is being said twice, it would be massively appreciated.

Thanks.

0
Is it possible that you can add the local script? User#41156 0 — 3y
0
I have put the local script on in this edit. KarateKid147 4 — 3y

Answer this question