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

Calling a function by chat?

Asked by 10 years ago

Would this work to call a function by chat?

game.Players.PlayerAdded:connect(function(pName)
    pName.Chatted.chat()
end)

2 answers

Log in to vote
0
Answered by 10 years ago

You were so close! Good job!

Your only mistake was line 2.

game.Players.PlayerAdded:connect(function(pName)
    pName.Chatted:connect(function (msg)
        -- Code
        -- Example code:

        if msg == "hi" then
            m = Instance.new("Message")
            m.Text = pName.Name ..' said "hi!" '
            wait(3)
            m:Destroy()
        end
    end)
end)

This would create a message with the Players name, then, 'said "hi!" '

Chat is an event under a Player, so it needs a connect. Much like the PlayerAdded, which is under players. Then, in your function, whatever you put in the ()'s are the

Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

This code is self explanatory. When a player is added, a Chatted event is attached to the player. The argument "message" is passed from the event.

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message)

    end)
end)

Answer this question