So, I've been trying to do chat commands and stuff, but when you say the command word in a sentence it doesn't activate. I THINK you have to use :match() for this? I don't know, so could anyone help me out? Here's the test code:
1 | local player = game.Players.LocalPlayer |
2 | local mouse = player:GetMouse() |
3 | player.Chatted:Connect( function (message) |
4 | if message:lower() = = "lumos" then |
5 | game.ReplicatedStorage.LumosEvent:FireServer(mouse.Hit.p) |
6 | end |
7 | end ) |
You can use string.sub,string.match, or string.find, most likely string.match or string.find
1 | local player = game.Players.LocalPlayer |
2 | local mouse = player:GetMouse() |
3 | player.Chatted:Connect( function (message) |
4 | if (message:lower()):match( 'lumos' ) then |
5 | game.ReplicatedStorage.LumosEvent:FireServer(mouse.Hit.p) |
6 | end |
7 | end ) |
You can use the message argument.
1 | local player = game.Players.LocalPlayer |
2 | local mouse = player:GetMouse() |
3 |
4 | player.Chatted:connect( function (msg) |
5 | if msg = string.lower( "lumos" ) then |
6 | game:GetService( "ReplicatedStorage" ).LumosEvent:FireServer(mouse.Hit.p) |
7 | end |
8 | end ) |