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

How do I make a Chat function?

Asked by 6 years ago

So what I'm needing is, When someone says a word, something happens. Its hard to explain, here is my script at the moment.

Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(Message)
        if Message == ("Lumos") then
            script.Parent.Handle.ParticlePart.Lumos.Enabled = true
        end
    end)
end)

I've tested with other things but I'm just not able to make this work.

(The script is in a Gear, the gear has a handle and in the is the mesh and particlepart, inside particlepart is a particle emitter. The gear is also in starter pack)

0
You may prefer to use Lua string patterns instead. Instead of Message == ("Lumos") you could try Message:match(".*Lumos.*") so that the player can say Lumos wherever in the sentence. NotInventedHere 158 — 6y

2 answers

Log in to vote
0
Answered by
FazNook 61
6 years ago
Edited 6 years ago

What you needed to do was to check if the player has equipped the tool and then initiate the chat function.

tool = script.Parent
particle = tool.Handle.ParticlePart.Lumos
player = game.Players.LocalPlayer
tool.Equipped:connect(function()
print('Enter')
player.Chatted:connect(function(msg)
    if string.lower(msg) == 'lumos' then
        print('Works')
        particle.Enabled = true
    end
end)

end)
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This is how i use player chatted functions just tweak it a little and it'll work.

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(Msg)
local msg = Msg:lower()
 if string.sub(msg, 1, 13) == "Lumos" then
 wait(0.1)
print("hi")
---------//do what you want here\\--------------
---------//you might need to add another end depending on what you write\\--------------
        end
    end)
end)

Answer this question