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

My script errors at line 3 - string expected got nil - How can i fix this?

Asked by 4 years ago

My script detects if somebody said walter and prints their name.Later i'm going to teleport to them but for now its print.

for i,currentPlayersChatting in pairs(game:GetService("Players"):GetPlayers()) do
    currentPlayersChatting.Chatted:connect(function(speaker, msg)
if string.lower(msg) == "walter" then
    print(speaker.Name)
end
    end)
        end
0
Please mark the answer as the solution so they can get points. Xapelize 2658 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The problem is that .Chatted does not have speaker and message. It only has message.

Read more about it here

Your fixed script would be:

for i,currentPlayersChatting in pairs(game:GetService("Players"):GetPlayers()) do
    currentPlayersChatting.Chatted:Connect(function(msg)
if string.lower(msg) == "walter" then
    print(currentPlayersChatting.Name)
end
    end)
        end

Also, keep in mind how .Chatted works is like this: PlayerInstance.Chatted.

0
Thank you so much this helped me greatly. misha123 83 — 4y
0
Can you accept it as answer in that case? GeneratedScript 740 — 4y
0
Yes so sorry I forgot misha123 83 — 4y
Ad

Answer this question