Table not working with TextButton

Hi, so what I am having issues with is, I am creating a table, which is supposed to look for available hotels for my game(1 player per hotel), without having 2 players in the same hotel. My effort in trying to achieve this is quite confusing, as I add a BoolValue into the parts itself and name the value “Enabled.” The problem is, I’m not quite sure how to achieve this with the textbutton which has a localscript:


disabled = false

script.Parent.MouseButton1Click:connect(function()
	if disabled == false then
		disabled = true
		game.Workspace.Teleport.RemoteFunction:InvokeServer()
		wait(3)
		disabled = false
	end
end)

The thing is, I don’t know how to apply the table data to a button, for example if a localscript was inside a button and when you click it, it checks the table for hotels that are currently not taken (BoolValue = Enabled), and it looks through and chooses Point B and teleports you there. <— This is what I am trying to achieve, please help!

4 Likes

What do you have on the server currently?

2 Likes

As of now, this is everything inside ServerScriptService:
Screenshot_23

Inside the script, I made a table and I would use in pair loops but I’m not sure how to apply it using the textbutton, in other words, I’m not sure what to put in the localscript inside of the textbutton itself.


local SpawnTable = {game.Workspace.TeleportPart1,game.Workspace.TeleportPart2,game.Workspace.TeleportPart3,game.Workspace.TeleportPart4,game.Workspace.TeleportPart5,game.Workspace.TeleportPart6,game.Workspace.TeleportPart7,game.Workspace.TeleportPart8,game.Workspace.TeleportPart9,game.Workspace.TeleportPart10,game.Workspace.TeleportPart11,game.Workspace.TeleportPart12,game.Workspace.TeleportPart13,game.Workspace.TeleportPart14,game.Workspace.TeleportPart15}


    game.Workspace.RemoteFunction.OnServerInvoke = function(player)
    local selected 
    for i, v in pairs(SpawnTable) do
        if v.Occupied.Value == false then
            selected = v
            break
        end
    end
    if not selected then 
        return "Can't find an empty hotel!"
    end
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        player.Character.HumanoidRootPart.CFrame = selected.Spawn.CFrame + Vector3.new(0,3,0)
        return true
    end
    return "Can't find player HumanoidRootPart!"
end
1 Like

I see, but would I still have the same script for the button itself:

yes, but i recommend you put the remote in ReplicatedStorage, and change :connect to :Connect

I should also point out that the hotels should all either be in a model or a folder. Then you could just do:

local SpawnTable = game.Workspace.Hotels:GetChildren()

It should (hopefully) work :smiley:
Your game should look a bit like this

game
     Workspace
          Hotels
               Hotel1
                    Occupied(BoolValue)
                    Spawn (Basepart)
               Hotel2
                    Occupied(BoolValue)
                    Spawn(BasePart)
1 Like

Yes I am currently testing it out at the moment, thank you for the help!

1 Like

i made a mistake on the last post,

if v.Occupied.Value == true then

should be

if v.Occupied.Value == false then

sorry my bad :sweat:

1 Like

Hey! It’s you again. Good to know that things are working out.

1 Like

Yes thank you for bringing up the table, it really helped considering I would’ve done something more manual rather than a table! :smiley:

1 Like

Hey so I’m testing it out but for some reason there are 2 errors:

  • one being:
  • also I messed around with some other settings, and fixed a couple errors but for some reason I can’t teleport to the actual part which I named “TeleportPart”

Teleport Button:


Please correct me anywhere if I made any mistake :slight_smile:

Oh im really sorry, the line:

game.Workspace.RemoteFunction.OnServerInvoke = function()

should be

game.Workspace.RemoteFunction.OnServerInvoke = function(player)

sorry my bad :sweat:
i just wrote that… thanks for letting me know !

1 Like