a = game.workspace.inside.Folder print("starting") randomseat = {a.a, a.b, a.c, a.d, a.e, a.f, a.g, a.h} seat = randomseat[math.random(1, #randomseat)] print(seat) print("good") if workspace:FindFirstChild("Player") then print("yes") game.Workspace.Player.HumanoidRootPart.CFrame = seat.Position print("yesyesyes") end
The random seat part of the code is when the player joins, the script needs to take a player to an open seat, just to clarify my intentions.
I have basically done prints to check where the script fails, I am not getting any errors, but the script is not working as intended. The output presents "starting", the seat letter(a-h[on random]), and good. However, it does not make it past the if statement. On top of that problem, I am having trouble teleporting the player to an open seat.
Some additional things that you might want to know:
I am using a regular script located as the child of the workspace
The seats are unions.
The unions go from game to workspace, to inside(Which is basically a room that is a model) to a folder, and the children of that folder are all the seats which are just a union.
I have been stuck on this problem for a week any help is appreciated, thanks!
local Players = game:GetService("Players") -- Place all your seat objects here 'local seats' local Seats = workspace:FindFirstChild("Seats") local SeatTbl = {} for _,v in next, Seats:GetDescendants() do if v:IsA("Seat") then table.insert(SeatTbl, v) end end -- When a player joins Players.PlayerAdded:Connect(function(Player) -- When their character is added Player.CharacterAdded:Connect(function(Char) wait() local Character = Char or Char.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") -- Getting a random free open seat. local ChosenSeat = SeatTbl[math.random(1, #SeatTbl)] if ChosenSeat.Occupant then -- Incase if someone is already sitting return else -- Sits on the found open seat. ChosenSeat:Sit(Humanoid) end end) end)
Please also make sure this is in a server script not an localscript. Hope this works.
Here. You're script was very OCD for these scripters. I have remade it for you! make a folder in workspace named "Seats" (Case Sensitive) and drag all of your seats inside of the folder. This will teleport all players to a random seat.
print("starting") local randomseat = game.Workspace.Seats:GetChildren() print("good") wait(2) for i,v in pairs (game.Players:GetChildren()) do print("yes") local seat = randomseat[math.random(1, #randomseat)] print(seat) v.Character.HumanoidRootPart.CFrame = seat.CFrame + Vector3.new(0, i * 5, 0) print("yesyesyes") end