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

Saying certain message while on a part detection script not working?

--I'm trying to learn how to detect if a player is saying a certain chat message while they're on a certain part. If ROBLOX detects that, then in the output, it will print "i". Here's the script:

local player = game.Players.LocalPlayer

player.Character.Chatted:connect(function(msg)
	if msg=="I am me." then
                for i,v in pairs(game.Workspace.Bathroom.Rug:GetTouchingParts()) do
                        if v.Parent == player.Character then
                               print("i")
                                break
                         end
                end
	end
end)

-- I know this doesn't work because the output doesn't print "i" and it says, "Workspace.I am me:3: attempt to index local 'player' (a nil value)". Could someone help?

1 answer

This should be a local script... That error says "player" is nil or means nothing. So the line that set up player is broken. The only reason I could see is, its not in a local script. Or maybe do something like

game.Players.ChildAdded:connect(function(player) 
player.Chatted:connect(function(msg)
if msg=="I am me." then
for i,v in pairs(game.Workspace.Bathroom.Rug:GetTouchingParts()) do
if v.Parent == player.Character then
     print("i")break
end end end
end) end)

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