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 5 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.

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

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 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:

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

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

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

Answer this question