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

My Jail script isn't working?

Asked by
Scriptecx 124
9 years ago

I honestly have no Idea what is wrong with this. It gets past the chat function but then when it gets to the line the command is on it stops. Would anyone know what might be the cause of this?

Jailed = {"Player"}
Jail = game.Workspace.JailBrick

function CheckJail (player)
    for _, p in pairs (Jailed) do
        if player.Name == p then
            return true
        end
    end
    return false
end

function findPlayer(name)
    for _, v in pairs(game.Players:GetPlayers()) do
            if string.find(string.lower(v.Name),string.lower(name)) then
                    return v
            end
        end
end

game.Players.PlayerAdded:connect(function(player)
    print (CheckJail(player))
    if CheckJail (player) == true then
        player.CharacterAdded:connect(function(Character)
            if player and Character and Character:FindFirstChild ("Humanoid") and  Character:FindFirstChild ("Humanoid").Health > 1 then
                print ("Jailing "..player.Name.."...") 
                wait ()
                Character.Torso.CFrame = CFrame.new(Jail.Position) * CFrame.new(0, 3, 0)
            end
        end)
    end
    player.Chatted:connect(function(msg)
        msg = msg:lower()
        print (player.Name.." Has chatted!")
        if msg:sub(1,6) == ";Jail " then
            print (player.Name.." Has chatted the command "..msg:sub(1,6))
            local vic = findPlayer(msg:sub(7))
            if CheckJail(vic) == false then
                print ("Jailing "..vic.Name.."...") 
                if vic and vic.Character and vic.Character:FindFirstChild ("Humanoid") and  vic.Character:FindFirstChild ("Humanoid").Health > 1 then
                    vic.Character.Torso.CFrame = CFrame.new(Jail.Position) * CFrame.new(0, 3, 0)
                end
                table.insert(Jailed, vic)
            end
        elseif msg:sub(1,8) == ";Unjail " then
            print (player.Name.." Has chatted the command "..msg:sub(1,8))
            local vic = findPlayer(msg:sub(7))
            if CheckJail(vic) == true then
                print ("UnJailing "..vic.Name.."...") 
                vic:LoadCharacter()
                table.remove(Jailed, vic)
            end
        end
    end)

0
You're missing an `end)` at the end of the script. Validark 1580 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
Jailed = {"Player"}
Jail = game.Workspace.JailBrick

function CheckJail (player)
    for _, p in pairs (Jailed) do
        if player.Name == p then
            return true
        end
    end
    return false
end

function findPlayer(name)
    for _, v in pairs(game.Players:GetPlayers()) do
            if string.find(string.lower(v.Name),string.lower(name)) then
                    return v
            end
        end
end

game.Players.PlayerAdded:connect(function(player)
    print (CheckJail(player))
    if CheckJail (player) == true then
        player.CharacterAdded:connect(function(Character)
            if player and Character and Character:FindFirstChild ("Humanoid") and  Character:FindFirstChild ("Humanoid").Health > 1 then
                print ("Jailing "..player.Name.."...") 
                wait ()
                Character.Torso.CFrame = CFrame.new(Jail.Position) * CFrame.new(0, 3, 0)
            end
        end)
    end
    player.Chatted:connect(function(msg)
        msg = msg:lower()
        print (player.Name.." Has chatted!")
        if msg:sub(1,6) == ";Jail " then
            print (player.Name.." Has chatted the command "..msg:sub(1,6))
            local vic = findPlayer(msg:sub(7))
            if CheckJail(vic) == false then
                print ("Jailing "..vic.Name.."...") 
                if vic and vic.Character and vic.Character:FindFirstChild ("Humanoid") and  vic.Character:FindFirstChild ("Humanoid").Health > 1 then
                    vic.Character.Torso.CFrame = CFrame.new(Jail.Position) * CFrame.new(0, 3, 0)
                end
                table.insert(Jailed, vic)
            end
        elseif msg:sub(1,8) == ";Unjail " then
            print (player.Name.." Has chatted the command "..msg:sub(1,8))
            local vic = findPlayer(msg:sub(7))
            if CheckJail(vic) == true then
                print ("UnJailing "..vic.Name.."...") 
                vic:LoadCharacter()
                table.remove(Jailed, vic)
            end
        end
    end)
end)

You were missing an 'end)' to close the function at line 21

Ad

Answer this question