Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

:elevator ham instead of :elevator hamidismylife?

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

1 comment

0

Just lower both the chatted input and the player found in players, if there is a match (preferably :match) then you can do some variable magic and make the variable the found player

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.