Seating System Not Working

Salutations. I have been working on a seating system when an Administrator (or someone whom has the permission to use the command) says !seat it will bring a random player whom is sitting in the lobby seats to the interview/training room seats. When I run the command it cannot find the player whatsoever. Is anyone able to help me with this, or give some feedback?

My Code:

function FindPlayer(Username)
for i,Player in pairs(game.Players:GetPlayers()) do
if string.sub(string.lower(Player.Name), 0, string.len(Username)) == string.lower(Username) then
return Player
else
end
end
end

game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if Player:GetRankInGroup(5706574) >= 0 then
if string.sub(msg:lower(),1,5) == “!seat” then
local SplitMessage = string.split(msg, " ")
local SelectedPlayer = FindPlayer(SplitMessage[2])

            if SelectedPlayer.Character.Humanoid.Sit == false then
                for i,v in pairs(workspace.Seats:GetChildren()) do
                    if v.Occupant == nil then
                        SelectedPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(v.Position)
                        break
                    end
                end
            end
        end
    end
end)

end)

2 Likes

It apparently glitched the scripting text…

If there’s a bug that you do not know where it is located, try printing things in between.

Also, I copied and pasted the script into studio. There was a bug in “!seat”. When I changed the quotation marks there were no errors. Try that. :slightly_smiling_face:

1 Like

Test this

function FindPlayer(Username)
     for i,Player in pairs(game.Players:GetPlayers()) do
           if string.sub(string.lower(Player.Name), 0, string.len(Username)) == string.lower(Username) then
              return Player
             else
           end
    end
end

game.Players.PlayerAdded:Connect(function(Player)
     Player.Chatted:Connect(function(msg)
          if Player:GetRankInGroup(5706574) >= 0 then
              if string.sub(msg:lower(),1,5) == “!seat” then
              local SplitMessage = string.split(msg, " ")
              local SelectedPlayer = FindPlayer(SplitMessage[2])
              if SelectedPlayer.Character.Humanoid.Sit == false then
                for i,v in pairs(workspace.Seats:GetChildren()) do
                    if v.Occupant == nil then
                        v:Sit( SelectedPlayer.Character.Humanoid)
                        break
                    end
                end
            end
        end
    end
end)

Just use Seatgoeshere:Sit(humanoidgoeshere) to make a player sit on a seat.

I think this code should work.



local sitcommand = "/sit"

game.Players.PlayerAdded:Connect(function(plr)

plr.Chatted:Connect(function(msg)
  if msg:sub(1, sitcommand:lens()):lower == sitcommand  and plr:GetRankInGroup() <= 230 then
     for i, v in pairs(plr:GetPlayers()) do
         local randomnumber = math.random(1,15)
if i == randomnumber and v:GetRankInGroup() >= 0 then
       v.Character.HumanoidRootPart.CFrame = game.Workspace.Seat.CFrame
end

     end
             end


                       end