Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

Please mark the answer as the solution so they can get points.

1 answer

✓ Accepted answer

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.

3 comments

0

Thank you so much this helped me greatly.

0

Can you accept it as answer in that case?

0

Yes so sorry I forgot

This discussion is preserved as it was. New answers, comments, and votes are closed.