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

:elevator ham instead of :elevator hamidismylife? [closed]

Asked by 4 years ago
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
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 SmartNode 383 — 4y

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?

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad