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

Certain Player Chatted Function?

Asked by
Burobuu 18
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

Answer this question