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

Certain Player Chatted Function?

I've recently tried to make a script where it only runs when a certain player(s) say something in the chat. When the script runs the scripts Parent or the "door" will open. The script will have two functions so when the player(s) say "StoreOpen" it opens and when the players say "StoreClose" it closes.

what my trashy self came up with

door = script.Parent 

function onChatted(msg, recipient, speaker) 
local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if (msg == "open") then 
door.CanCollide = false 
door.Transparency = 0.7 
wait(5) 
door.CanCollide = true 
door.Transparency = 0 
end 

end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

1 answer

✓ Accepted answer

You would use the speaker to reference the player:

door = script.Parent 

function onChatted(msg, recipient, speaker) 
local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if speaker.Name == "Your Name here" then
	if (msg == "open") then 
		door.CanCollide = false 
		door.Transparency = 0.7 
		wait(5) 
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end

end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

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