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

Anyway I can make it so I don't have to type the players full name when using the jail command?


permission = {"ClearlyDeveloped"}

jail = game.Workspace.IndependentStudyRoomBlock.Block

function check(name)
    if table.maxn(permission) == 0 then return true end
        for i = 1,#permission do
        if (string.upper(name) == string.upper(permission[i])) then return true end
        end
    return false
end

function Jail(name)
    local player = game.Players:FindFirstChild(name)
    local torso = player.Character:FindFirstChild("Torso")
    if torso == nil then return end
        local location = {jail.Position}
        local i = 1

        local x = location[i].x
        local y = location[i].y
        local z = location[i].z

        x = x + math.random(-1, 1)
        z = z + math.random(-1, 1)
        y = y + math.random(2, 3)

        local cf = torso.CFrame
        local lx = 0
        local ly = y
        local lz = 0

    torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
end

function onChatted(msg, recipient, speaker)

    local source = string.lower(speaker.Name)
    msg = string.lower(msg)

    if not check(source) then return end

        if string.match(msg, "!jail") then
            local players=game.Players:GetChildren()
            for i=1, #players do
                if string.match(msg, string.lower(players[i].Name)) then

                    Jail(players[i].Name)

                return
            end
        end
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)



2 comments

0

use string.sub() for this

0

Could you put it in the script for me please? Not that smart. Lmao.

2 answers

✓ Accepted answer

From line 45-51, replace the code with this:

for _,player in pairs(players) do
	local Array = {}
	for i = 1,string.len(player.Name) do
		table.insert(Array,string.sub(player.Name,1,i))
	end
	for i,v in pairs(Array) do
		if string.match(msg,string.lower(v)) then
			Jail(player.Name)
		end
	end
end

I hope this works, as it took me sometime to figure it out!

2 comments

0

Amazing! Thank you both so so much.

0

welcome

This also works (didn't notice it got answered until just now ;p)

permission = {"ClearlyDeveloped"}

jail = game.Workspace.IndependentStudyRoomBlock.Block

function check(name)
    if table.maxn(permission) == 0 then return true end
        for i = 1,#permission do
        if (string.upper(name) == string.upper(permission[i])) then return true end
        end
    return false
end

function Jail(name)
    local player = game.Players:FindFirstChild(name)
    local torso = player.Character:FindFirstChild("HumanoidRootPart")
    if torso == nil then return end
        local location = {jail.Position}
        local i = 1

        local x = location[i].x
        local y = location[i].y
        local z = location[i].z

        x = x + math.random(-1, 1)
        z = z + math.random(-1, 1)
        y = y + math.random(2, 3)

        local cf = torso.CFrame
        local lx = 0
        local ly = y
        local lz = 0

    	torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
end

function onChatted(msg, recipient, speaker)

    local source = string.lower(speaker.Name)
    msg = string.lower(msg)

    if not check(source) then return end
	
	if string.match(msg, "!jail") then
		local plrname = FindPlayer(msg)
		if plrname ~= nil then
			Jail(plrname)
		end
	end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

function FindPlayer(msg)
	local players=game.Players:GetChildren()
	local msgFinder = string.split(msg, ' ')
	local plrName = string.lower(msgFinder[2])
	local plrNameLength = string.len(plrName)
	local plr = nil
	
	for i=1, #players do
        if string.match(plrName, string.sub(string.lower(players[i].Name), 1, plrNameLength)) then
			plr = players[i].Name
		end
	end
	
	return plr
end

game.Players.ChildAdded:connect(onPlayerEntered)

1 comment

0

Much appreciated.

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