How to make a hotel room system

:warning: You need to know basic scripting before you read this tutorial

Also, note that this is a basic tutorial for getting the idea on how to make a hotel system on your own, not a community resource to copy paste, so the design of gui in this tutorial maybe bad, and this is just an idea, so there won’t be much stuff, but shows the basic way for making a hotel system

After reading the tutorial, you will be able to make your custom hotel system like this:

Some words to learn:

  • StringValue = An instance(object) value, which have a string as its value
  • IntValue = An integer value not decimals
  • NumberValue = Any whole number, decimals too

Check in systems:

  1. Card to open door
    2.Open door when touched
    These are for opening doors, not for making the check in system

The 2nd one is a bit harder for beginners, if your not a beginner then no worry

Check in system tutorial:

Step 1

image

Add a Folder in workspace, add string values, with names as room numbers as shown above

Step 2

image
Add a remote event in ReplicatedStorage for messaging between server and client side

Step 3

Make your gui for check in

Examples for Hotel UI


Make sure you have a texbox in your gui to enter the player name to give the hotel room key

Step 4

Now we make the thing which sends the message to server to get a room for the player name entered

Add a local script in your button which will give player the room key

Script: (Don’t try to copy paste :D)

script.Parent.MouseButton1Click:Connect(function()
    local playerchosen = nil
    local haveroomalready = false
    local playernameentered = script.Parent.Parent.TextBox.Text:lower()
    for i,v in pairs(game.Players:GetPlayers()) do -- checks if a player entered in textbox exist in the server
        if v.Name:lower() == playernameentered then -- :lower() means it makes any uppercase letter in the word or sentence a lowercase letter
            playerchosen = v -- if a player like that exist in server then we set the player chosen variable as this player
        end
    end
    if playerchosen ~= nil then -- if someone is chosed then do this function below
        for i,v in pairs(game.Workspace.Rooms:GetChildren()) do -- this line checks all the room numbers ,if the player owns any room
            if v:IsA("StringValue") then
                if v.Value == playerchosen.Name then
                    haveroomalready = true -- this variable changes its value to true, so it means player have room already
                end
            end
        end
        if haveroomalready == false then -- if the player don't have a room already then they get a room
            game.ReplicatedStorage.GetHotelRoomEvent:FireServer(playerchosen) -- sends message to server
        end
    end
end)

Step 5

A script in server script service or in workspace, anything is fine
Script:

game.ReplicatedStorage.GetHotelRoomEvent.OnServerEvent:Connect(function(plr,plrtogiveroom)
    local roomchosen = nil -- no room is chosen, later it gets chosen
    for i,v in pairs(game.Workspace.Rooms:GetChildren()) do
        if v.Value == "" then -- this checks if the room is vacant
            roomchosen = v -- sets the chosen room to the room which is vacant
        end
    end
    if roomchosen ~= nil then -- if a room is vacant
        roomchosen.Value = plrtogiveroom.Name
    else
        print("No room is vacant") -- it prints no room is vacant if no room is available
    end
    local tool = Instance.new("Tool",plrtogiveroom.Backpack) -- gives the room key to player
    tool.Name = roomchosen.Name.." Room key"
end)

Step 6

Now test it, it works and your happy that you made a hotel system

Now, there is one more thing, you need to remember, check-out rooms and rooms should get vacant if player leaves the server

This one is not hard at all, if you understood how to make this check-in system, you will understand check-out system to

As mentioned, you need to know some basic scripting before watching the tutorial, so I am not telling how to open/close door with the room key you got

Try to do it yourself, its easy and you would be proud that you did something yourself without watching any tutorial

Now to make a check out system

  • Add another remote event
    image
  • Name it anything you would like to

Script in workspace or server script service:

game.ReplicatedStorage.CheckoutEvent.OnServerEvent:Connect(function(plr,plrtocheckout)
    for i,v in pairs(game.Workspace.Rooms:GetChildren()) do -- checks all rooms if player have any room
        if v:IsA("StringValue") then
            if v.Value == plrtocheckout.Name then -- if room is occupied by the player name
                v.Value = "" -- make it vacant
                plr.Backpack:ClearAllChildren() -- clears all the stuff in player backpack including hotel key
                print("Check-out done")
            end
        end
    end
end)

Step 7

Add check out button to your gui

Also make sure both the text box have different names
image

Step 8

Add a local script in your textbutton
Script:
This is same like check in system, but a different thing is this is opposite of it

script.Parent.MouseButton1Click:Connect(function()
    local playerchosen = nil
    local haveroomalready = false
    local playernameentered = script.Parent.Parent.TextBox.Text:lower()
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.Name:lower() == playernameentered then
            playerchosen = v
        end
    end
    if playerchosen ~= nil then
        for i,v in pairs(game.Workspace.Rooms:GetChildren()) do
            if v:IsA("StringValue") then
                if v.Value == playerchosen.Name then
                    haveroomalready = true
                end
            end
        end
        if haveroomalready == true then -- if player have room then check out them
            game.ReplicatedStorage.CheckoutEvent:FireServer(playerchosen)
        end
    end
end)

That’s it your done, hotel system check-in, check-out is done, but if you want the room to be vacant when player leaves do this script:

game.Players.PlayerRemoving:Connect(function(plrtocheckout)
    for i,v in pairs(game.Workspace.Rooms:GetChildren()) do
        if v:IsA("StringValue") then
            if v.Value == plrtocheckout.Name then
                v.Value = ""
                print("Check-out done")
            end
        end
    end
end)

Tutorial is done, some scripts may not have been explained much, but if you know basic scripting thats easy, because I did not do any hard stuff in this tutorial which basic scripters cannot understand

Since its a long tutorial, some people might be bored to see it fully, but I am sure you will know how to make a hotel system for sure

Support me

Hey there, I make alot of tutorials, and if you want to help me please donate below
Paypal

10 Likes

Just a info, this works on all devices

3 Likes

Would prefer if you just declare the service at the beginning of the script.

Also, I wouldn’t use a for loop just to get the targeted player. I would just use :FindFirstChild().

workspace over game.Workspace.

Again, declare the service at the beginning of the script.

I would recommend people to put it in ServerScriptService for the sake of organization.

workspace.

After they chose a room, you should break the loop to prevent them from getting the very last room. (If you want them to get the earliest rooms of course.)

This should be inside the if statement, because it would still give out the key even though if the player didn’t get any empty rooms.

workspace.

Again, break the loop to avoid unnecessary checks of other rooms.

I wouldn’t say this tutorial is bad, nor is good. Just need some more improvements, such as giving better names for the variables and instances.

I hope my suggestion helps.

4 Likes

You cannot do that, as there won’t be a value in the folder with name of the player

Yes you can do that, but that just increases the script length, some people think big scripts means harder, so they stop reading tutorial, to avoid that I made the script smaller, and it works too


Yes, I know but not many basic scripters know how to break loops, and they get confused when and how to break, so I did not include it too

Its ok, but you will still get a room even if its a last room

1 Like

I don’t get what you’re saying.

It’s literally just one line of code, and no one is going to quit reading a tutorial if they are determined to learn.

You should include it so your learners can actually learn something new instead of just sticking old skills.

3 Likes
  • It’s better to use the shorter workspace instead of typing out game.Workspace.
  • Try using attributes instead of value objects, as it’s possible in this case.
2 Likes

I am sorry but what is folder actually used for, like what is it meant to do??

Also did you spell textbox wrong? It says “texbox”.

The OP is you, ‘original poster’, and I don’t see anything wrong with this post. The information given is helpful, as I don’t recommend the ways you have written this code either.

Critique of tutorials is EXTREMELY important, so the beginner (who won’t know anything) knows the most efficient way of writing code. Critique can also identify which tutorials are good and which are bad.

Simply, this user (and a few others) has highlighted some things which users should avoid.

2 Likes

The folder contains all the room numbers, and they are all string values

If their value is empty/blank/vacant then room is free, if its not vacant then its value is some player’s name

Yes, its textbox it was spelled wrong

Sure, but I forgot that, so I didn’t show that anyways this works too, I don’t wanna make another tutorial xd

Using attributes instead of value objects in this case actually makes the code shorter and slightly more efficient.

For example, your following code:

for i,v in pairs(game.Workspace.Rooms:GetChildren()) do -- checks all rooms if player have any room
    if v:IsA("StringValue") then
        if v.Value == plrtocheckout.Name then -- if room is occupied by the player name
            v.Value = "" -- make it vacant 
            plr.Backpack:ClearAllChildren() -- clears all the stuff in player backpack including hotel key
            print("Check-out done")
        end
    end
end

would become:

for i, v in pairs(workspace.Rooms:GetAttributes()) do -- checks all rooms if player have any room
    if v == plrtocheckout.Name then -- if room is occupied by the player name
        workspace.Rooms:SetAttribute(i, "") -- make it vacant 
        plr.Backpack:ClearAllChildren() -- clears all the stuff in player backpack including hotel key
        print("Check-out done")
    end
end
1 Like

Also, when checking out, you should only make sure to clear the player’s hotel key and not their entire backpack. In fact, doing plr.Backpack:ClearAllChildren() won’t actually work for equipped tools which are parented to the player’s character.

Yes, but ||I don’t know how to use Attributes that much xd||

Oh yes, I forgot it, will update the post

1 Like

It’ll be useful to read up about it: Instance Attributes | Roblox Creator Documentation

1 Like

whole number is the opposite of decimal hehe. good tutorial though

1 Like

This looks cool! I may use an upgraded and changed version of it in my game.

1 Like

Yes, this is a tutorial showing how to make a basic hotel room system, however once you know how it works, then you can make one on your own

Good luck making one ;D