plr = game:GetService("Players").LocalPlayer plz = game:GetService("Players") plr.Chatted:Connect(function(msg) if string.find(msg,":elevator") then for i,v in pairs(plz:GetPlayers()) do if string.find(string.lower(msg),string.lower(v.Name)) then while true do wait() plz:chat(":jail".." "..v.Name) end end end end end) do you know how to make it so i dont have to say :elevator hamidismylife i can say :elevator ham
Okay I will be solving 2 problems simultaneously here, Chatted
works best on the server, whilst :Chat()
only works on the client. I use the string.match
method quite frequently, so I'll use it here. Another problem I found is that your script acted a little oddly, so I'm changing it a little.
SCRIPT IN SERVERSCRIPTSERVICE
Players = game:GetService("Players") function getPlayer(Args) local tab = {} for _,plr in pairs(Players:GetPlayers()) do if plr.Name:lower():sub(1,Args:lower():len()) == Args:lower() then table.insert(tab,#tab+1,plr) end end return tab end Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) local cmd,args = msg:match("(.-) (.+)") if cmd:lower() == ":elevator" then for i,v in pairs(getPlayer(args)) do print(":jail "..v.Name) end end end end)
Edit: I removed the chat part you were trying to do as I have no idea what your aims are, but you can't make the Players class chat... If this doesn't work, please DM me on Discord. MachoPiggies#3484
Closed as Non-Descriptive by whenallthepigsfly, EpicMetatableMoment, Igoralexeymarengobr, namespace25, and MachoPiggies
This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.
Why was this question closed?