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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
Bellyrium 310 Moderation Voter
6 years ago
Edited 6 years ago

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)
Ad

Answer this question