You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want to know why my script works, but throws an error at my face (not literally lol)
What is the issue?
I get this error every time I run the following script.
Script:
local frame = script.Parent.Parent
local textLabel = frame:WaitForChild("Text")
local characterImage = frame:WaitForChild("CharacterImage")
local characterImageModule = require(game:GetService("ReplicatedStorage").CharacterImages)
function write(Label, message, duration)
print(Label, message, duration)
Label.Text = ""
local split = string.split(message, "")
for i, v in pairs(split) do
script.tap:Play()
Label.Text = Label.Text .. v
wait(0.085)
end
wait(tonumber(duration))
Label.Text = ""
script.Parent.Parent.Parent.Enabled = false
end
game:GetService("ReplicatedStorage").Events.Talk.OnClientEvent:Connect(function(message, name)
print("We are talking to an NPC!")
local imageId = characterImageModule[name]
print(imageId)
if imageId and textLabel.Text == "" then
characterImage.Image = imageId
script.Parent.Parent.Parent.Enabled = true
print(typeof(textLabel), typeof(message), typeof(3))
textLabel.Text = write(textLabel, message, tonumber(3)) -- the line that errors
script.Parent.Parent.Parent.Enabled = false
textLabel.Text = ""
end
end)
Put this on the line above and let me know what it says. print(textLabel, message, tonumber(3))
Also, 3 is already a number and you don’t need to use tonumber on it.
Text - I hear there is some nerd kid who collects bugs. You might find him at the boy's cabin. - 3 (I added the dashes so you can clearly see the individual items.)
I only used the tonumber() function as the error saidinvaild argument #3. So, I thought it was reading the number 3 as nil or something. Plus, using the function will not change a number to a number if its already a number. (I also already tried that)
Never mind, it was a shot in the dark because I’m dumb and couldn’t find the problem.
It looks like your problem is that write doesn’t return a string.
If I’m reading it right, the solution is to change the line to this. write(textLabel, message, 3)
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Variables
local frame = script.Parent.Parent
local textLabel = frame:WaitForChild("Text")
local characterImage = frame:WaitForChild("CharacterImage")
-- Modules
local characterImageModule = require(ReplicatedStorage.CharacterImages)
local function ClearTextLabel()
if textLabel.Text == "" then
return
else
textLablel.Text = ""
end
end
local function GuiEnabled(state)
script.Parent.Parent.Parent.Enabled = state
end
local function Typewrite(Message, Duration)
ClearTextLabel()
for i = 1, #Message then
textLabel.Text = string.sub(Message,1,i)
wait(0.085) -- Or duration
end
wait(Duration)
ClearTextLabel()
GuiEnabled(false)
end
ReplicatedStorage:WaitForChild("Events"):WaitForChild("Talk").OnClientEvent:Connect(function(message, name)
local imageId = characterImageModule[name]
if imageId then
characterImage.Image = imageId
GuiEnabled(true)
typewrite(message, 3)
GuiEnabled(false)
end
end
Okay so while I was rewriting the script I released that the error could be that you did textLabel.Text = write(textLabel, message, tonumber(3)) you should try and put write(textLabel, message, 3)
Hello. This doesn’t really answer your question; however I believe there is a much easier way of achieving this effect and cleaner by using the MaxVisibleGraphemes property.
Your module could look something like this:
local SpacePeriod = 0.06
local SetenceMarkerPeriod = 2
local module = {
["Ecris"] =
function(TextToType)
local index = 0
local success,err = pcall(function()
for first, last in utf8.graphemes(TextToType.Text) do
local grapheme = TextToType.Text:sub(first, last)
index = index + 1
TextToType.MaxVisibleGraphemes = index
if grapheme == "." or grapheme == "!" or grapheme == "?" then
wait(SetenceMarkerPeriod)
elseif grapheme == " " then
wait(SpacePeriod)
else
wait()
end
print(grapheme)
end
end)
end,
}
return module
And you would call this function from a local script like this: