Help with NPC script (again)

Thanks, but I’m gonna use @PostVivic’s method, as any characters with lines over 4 pages would glitch.

1 Like

Alright np! Maybe for someone else with a similar problem.

1 Like

My dialogue thing is using 2 lines, and I don’t know what changes to make, could you tell me what to do?

Also, for the arguments (Adornee, Dialogue, GuiObject) would I still need Adornee and GuiObject? I’m using a single ScreenGUI.

Adornee was just for the VPFrame. But i would keep it if you wanted the NPC to point towards you in a cutscene like thing, GUIObject was just to shorten my code… Wdym dialogue thing is using 2 lines?

1 Like

So I wouldn’t need Adornee or GUIObject.

For dialogue 2 lines, I meant I’m using 2 TextLabels for my dialogue, what would I do in that case?

  1. exactly
  2. Why would you use 2 textlabels? use 1 with TextScaled Enabled
1 Like

Would there be a way to make the dialogue so that it wraps around while being scaled?

yes, using textWrapped property

1 Like

When I use TextWrapped, and TextScaled, it doesn’t work, so would I have to use only TextWrapped?

(I want my dialogue to be scaled on all devices, and I’ve never really tried before, so I don’t really know how)

just textwrapped if you want the thing to stay the same

1 Like

because textscaled is off, it clips the actual words and makes them out of the textbox.

1 Like

I’ve been editing your code to fit mine, and I got stuck on the DummyText() function.

Could you help me?

Code so far
local talkModule = {}


function talkModule:InitTalk(Dialogue)
--function talkModule:InitTalk(Adornee, Dialogue, GuiObject)
	--This module was designed for multiple dialogues.
	--So you can have different people saying different stuff
	local textlabel1 = script.Parent:WaitForChild("Main"):WaitForChild("Text1")
	--local textlabel2 = script.Parent:WaitForChild("Main"):WaitForChild("Text2")
	local proceed = script.Parent:WaitForChild("Main"):WaitForChild("Proceed")
	--local VPFrame = GuiObject.ViewportFrame--Set this to your VPFrame
	--local DialogueBox = GuiObject.DialogueBox--Set this to your dialogue box
	--local NextButton = GuiObject.NextButton--Set this to your nextButton
	--local OutOfScreenPosition = UDim2.new(0.5,0,1.2,0)--Set this to your out of screen position
	--local InScreenPosition = UDim2.new(0.5, 0, 0.98, 0)--Set this to your current ScreenPosition
	--local CameraOffset = Vector3.new(0,0,-2)--Set this to your Vector3 CameraOffset of the head
	local TypewriteWaitTime = 0.001--Set this to how fast your Typewrites wait time is

	textlabel1.Text = ""--Clearing the current text
	--textlabel2.Text = ""--Clearing the current text
	local StopTypewrite = false--A bool value we test for to show the rest of the dialogue

	--local TweenSpeed = 0.2--Here is the tween speed or how fast you want your gui to go
	--GuiObject.Position = OutOfScreenPosition--Setting the position to the out of screen thing again
	--for i,v in pairs(VPFrame:GetChildren()) do
	--	v:Destroy()--Destroying everything in the VPFrame
--	end
	--local VPAvatar = Adornee:Clone()--Clones the Dummy
	--VPAvatar.Parent = VPFrame--Sets dummy's parent to VPFrame

	--Viewport frames have a currentCamera and then renders any of its children
	--Its how Arsenal makes its character thingy

--	VPAvatar.HumanoidRootPart.CFrame = CFrame.new(0,0,0)
	--Setting HRP to 0,0,0 so the camera will position correctly
	--local VPCam = Instance.new("Camera", VPFrame)--Create Camera
--	VPCam.CFrame = VPAvatar.Head.CFrame + CameraOffset--Offseting Camera
--	VPCam.CFrame = CFrame.new(VPCam.CFrame.Position, VPAvatar.Head.CFrame.Position)
	--Pointing Camera towards head
	--GuiObject.ViewportFrame.CurrentCamera = VPCam--Setting CurrentCamera of the VPFrame to the camera
	--GuiObject:TweenPosition(InScreenPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, TweenSpeed)
	--The Line Above is Tweening the Gui Position
	--Enum.EasingDirection is only used if you dont use Linear
	--Enum.EasingStyle is the style of the tween, Look into different styles and easingDirections
	--TweenSpeed is how fast it will tween
	--wait(TweenSpeed)--Wait for it to finish tweening


	local function typewrite(object, text)

		--The typewrite function is same except for the stop typewrite code
		for i = 1,#text,1 do
			if not StopTypewrite then --Stopping is false
				object.Text = string.sub(text,1,i)
				wait(TypewriteWaitTime) --Not every frame, cant even read that stuff
				--Especially if some rat unlocks their fps to 1000
			else
				--Stops the typing and breaks the loop
				object.Text = text
				StopTypewrite = false
				break
			end
		end
	end


	local function DummyText()
		local Finished = false
		--Debounce
		local RepeatIndex = 0
		local Event
		local debounce = false-- Is the typewriter still running?
		local function InitTypewrite(actionName, inputState)
			if actionName then
				if inputState ~= Enum.UserInputState.End then
					--inputState needs to be end
					return
				end
				if actionName ~= "Typewrite" then
					return
				end
			end
			if debounce then StopTypewrite = true return end --Is typewriter still running?
			--if so then set StopTypewrite to true
			RepeatIndex = RepeatIndex + 1--Add one to the RepeatIndex
			if Dialogue[RepeatIndex] then--Is there another one after this?
				--Initiate Typewrite
				debounce = true
				typewrite(DialogueBox, Dialogue[RepeatIndex])
				debounce = false
			else
				--Set Finished to true
				Finished = true
			end
		end
		InitTypewrite()--Say the first thing
		Event = NextButton.MouseButton1Click:Connect(function()
			InitTypewrite()
		end)
		CAS:BindAction("Typewrite", InitTypewrite, false, Enum.KeyCode.E, Enum.KeyCode.ButtonL1)
		--Binding Action To buttonPress


		repeat--Waits until finished is true
			wait(0.05)
		until Finished == true
		Event:Disconnect()
		--Disconnects the NextEvent
		GuiObject:TweenPosition(OutOfScreenPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, TweenSpeed)
		--Tweens the GUI back down
	end

	DummyText()
	--Initiates DummyText
end

return talkModule

What is the issue that you have? any errors?

I just don’t know where to go, I have a lot of questions.

Could you explain this? I don’t really get it.

local function InitTypewrite(actionName, inputState)
			if actionName then
				if inputState ~= Enum.UserInputState.End then
					--inputState needs to be end
					return
				end
				if actionName ~= "Typewrite" then
					return
				end
			end

Alright, Action Name and inputState will be nil if it was hit by the next button, Those checks are making sure that the action name is “Typewrite” and the inputState is the releasing of input (if you want it begin then do Enum.UserInputState.Begin). If i didnt have those checks then the function would fire whenever you press the button, and also when you release the button aswell.

1 Like

If mine was click to begin dialogue, what parts would I need to remove?

local function DummyText()
		local Finished = false
		--Debounce
		local RepeatIndex = 0
		local Event
		local debounce = false-- Is the typewriter still running?
		local function InitTypewrite()
			if debounce then StopTypewrite = true return end --Is typewriter still running?
			--if so then set StopTypewrite to true
			RepeatIndex = RepeatIndex + 1--Add one to the RepeatIndex
			if Dialogue[RepeatIndex] then--Is there another one after this?
				--Initiate Typewrite
				debounce = true
				typewrite(DialogueBox, Dialogue[RepeatIndex])
				debounce = false
			else
				--Set Finished to true
				Finished = true
			end
		end
		InitTypewrite()--Say the first thing
		Event = NextButton.MouseButton1Click:Connect(function()
			InitTypewrite()
		end)


		repeat--Waits until finished is true
			wait(0.05)
		until Finished == true
		Event:Disconnect()
		--Disconnects the NextEvent
		GuiObject:TweenPosition(OutOfScreenPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, TweenSpeed)
		--Tweens the GUI back down
	end

there, i removed the use of CAS

1 Like

What is your DialogueBox variable for?

The dialoguebox was passed into the typewrite function to be the box where it types it out

1 Like

After my edits, the script just doesn’t run.

Module
local talkModule = {}


function talkModule:InitTalk(Dialogue)
--function talkModule:InitTalk(Adornee, Dialogue, GuiObject)
	--This module was designed for multiple dialogues.
	--So you can have different people saying different stuff
	local DialogueBox = script.Parent:WaitForChild("Main"):WaitForChild("Text1")
	--local textlabel2 = script.Parent:WaitForChild("Main"):WaitForChild("Text2")
	local proceed = script.Parent:WaitForChild("Main"):WaitForChild("Proceed")
	--local VPFrame = GuiObject.ViewportFrame--Set this to your VPFrame
	--local DialogueBox = GuiObject.DialogueBox--Set this to your dialogue box
	--local NextButton = GuiObject.NextButton--Set this to your nextButton
	--local OutOfScreenPosition = UDim2.new(0.5,0,1.2,0)--Set this to your out of screen position
	--local InScreenPosition = UDim2.new(0.5, 0, 0.98, 0)--Set this to your current ScreenPosition
	--local CameraOffset = Vector3.new(0,0,-2)--Set this to your Vector3 CameraOffset of the head
	local TypewriteWaitTime = 0.001--Set this to how fast your Typewrites wait time is

	textlabel1.Text = ""--Clearing the current text
	--textlabel2.Text = ""--Clearing the current text
	local StopTypewrite = false--A bool value we test for to show the rest of the dialogue

	--local TweenSpeed = 0.2--Here is the tween speed or how fast you want your gui to go
	--GuiObject.Position = OutOfScreenPosition--Setting the position to the out of screen thing again
	--for i,v in pairs(VPFrame:GetChildren()) do
	--	v:Destroy()--Destroying everything in the VPFrame
--	end
	--local VPAvatar = Adornee:Clone()--Clones the Dummy
	--VPAvatar.Parent = VPFrame--Sets dummy's parent to VPFrame

	--Viewport frames have a currentCamera and then renders any of its children
	--Its how Arsenal makes its character thingy

--	VPAvatar.HumanoidRootPart.CFrame = CFrame.new(0,0,0)
	--Setting HRP to 0,0,0 so the camera will position correctly
	--local VPCam = Instance.new("Camera", VPFrame)--Create Camera
--	VPCam.CFrame = VPAvatar.Head.CFrame + CameraOffset--Offseting Camera
--	VPCam.CFrame = CFrame.new(VPCam.CFrame.Position, VPAvatar.Head.CFrame.Position)
	--Pointing Camera towards head
	--GuiObject.ViewportFrame.CurrentCamera = VPCam--Setting CurrentCamera of the VPFrame to the camera
	--GuiObject:TweenPosition(InScreenPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, TweenSpeed)
	--The Line Above is Tweening the Gui Position
	--Enum.EasingDirection is only used if you dont use Linear
	--Enum.EasingStyle is the style of the tween, Look into different styles and easingDirections
	--TweenSpeed is how fast it will tween
	--wait(TweenSpeed)--Wait for it to finish tweening


	local function typewrite(object, text)

		--The typewrite function is same except for the stop typewrite code
		for i = 1,#text,1 do
			if not StopTypewrite then --Stopping is false
				object.Text = string.sub(text,1,i)
				wait(TypewriteWaitTime) --Not every frame, cant even read that stuff
				--Especially if some rat unlocks their fps to 1000
			else
				--Stops the typing and breaks the loop
				object.Text = text
				StopTypewrite = false
				break
			end
		end
	end


	local function DummyText()
		local Finished = false
		--Debounce
		local RepeatIndex = 0
		local Event
		local debounce = false-- Is the typewriter still running?
		local function InitTypewrite()
			if debounce then StopTypewrite = true return end --Is typewriter still running?
			--if so then set StopTypewrite to true
			RepeatIndex = RepeatIndex + 1--Add one to the RepeatIndex
			if Dialogue[RepeatIndex] then--Is there another one after this?
				--Initiate Typewrite
				debounce = true
				typewrite(DialogueBox, Dialogue[RepeatIndex])
				debounce = false
			else
				--Set Finished to true
				Finished = true
			end
		end
		InitTypewrite()--Say the first thing
		Event = proceed.MouseButton1Click:Connect(function()
			InitTypewrite()
		end)


		repeat--Waits until finished is true
			wait(0.05)
		until Finished == true
		Event:Disconnect()
		--Disconnects the NextEvent
		--GuiObject:TweenPosition(OutOfScreenPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Linear, TweenSpeed)
		--Tweens the GUI back down
	end

	DummyText()
	--Initiates DummyText
end

return talkModule
LocalScript
local player = game.Players.LocalPlayer
local npcs = game.Workspace.NPCs
local Dummy = npcs.Dummy

local Dialogue = {
	"Testing1 Testing1 Testing1",
	"testing2 testing2",
	"Testing3 testing3",
	"Testing4 testing4 Testing4",
	

}
local talkmodule = require(script.Parent.TalkModule)

--[[Dummy.Head.Speak.Triggered:Connect(function()--Im using a ProximityPrompt in the dummy's head
	Dummy.Head.Speak.Enabled = false--setting it so the prompt is not enables
	SpeakModule:InitTalk(Dummy, Dialogue, gui.ScreenGui.Frame)--Initiates talking
	Dummy.Head.Speak.Enabled = true--setting it so the prompt is enabled after
end)
]]--
Dummy.Click.ClickDetector.MouseClick:Connect(function()
	
	--talkmodule.talkfunction(player)
	--Dialogue:


end)

Could you help me out again? Thanks!