I was trying to create a dialogue code for my game
and this error popped up, take a look at the code:
StarterPlayerScripts:
local currentEvent = game.ReplicatedStorage.customMessage
currentEvent.OnClientEvent:Connect(function(player: Player, text: string)
local defaultLastTime = 10
local ui = player.PlayerGui
local accumulatedMsg = ""
local length = string.len(text)
for i = 1, length do
local char = text:sub(i, i)
if tonumber(char) then
if accumulatedMsg ~= "" then
print(accumulatedMsg)
end
ui.dialogueplr.txt.Text = char
accumulatedMsg = ""
else
accumulatedMsg = accumulatedMsg .. char
end
wait(0.05)
end
if accumulatedMsg ~= "" then
-- i will just leave this blank
end
wait(defaultLastTime)
accumulatedMsg = ""
for i = length, 1, -1 do
local char = text:sub(i, i)
if tonumber(char) then
if accumulatedMsg ~= "" then
print(accumulatedMsg)
end
ui.dialogueplr.txt.Text = char
accumulatedMsg = ""
else
accumulatedMsg = char .. accumulatedMsg
end
wait(0.09)
end
end)
ServerScriptService code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local SENDING = 'Welcome!'
player:WaitForChild("PlayerGui",15)
wait(0.02)
game:GetService("ReplicatedStorage").customMessage:FireClient(player,SENDING)
end)
end)
The only error i get is at the StarterPlayerScripts code, at line 10, it says: invalid argument #1 to ‘len’ (string expected, got nil) and if u saw the server code you could see how i am sending a string to the client but it keeps saying it’s nil.