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

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

Asked by 4 years ago

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)
0
use string.sub() for this qChaos 86 — 4y
0
Could you put it in the script for me please? Not that smart. Lmao. ClearlyDeveloped 11 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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!

0
Amazing! Thank you both so so much. ClearlyDeveloped 11 — 4y
0
welcome HomieFirePGN 137 — 4y
Ad
Log in to vote
0
Answered by
BuDeep 214 Moderation Voter
4 years ago

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)
0
Much appreciated. ClearlyDeveloped 11 — 4y

Answer this question