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

Script isn't working, and I can't teleport the player to a seat?

Asked by 4 years ago
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!

0
try removing the quotation marks in workspace:FindFirstChild("Player") HappyTimIsHim 652 — 4y
0
no that just gives a global error AdministrativeFellow 13 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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.

0
I am getting (Workspace.Script:58: attempt to index upvalue 'Seats' (a nil value)) on line 14. I do not know how to fix that error AdministrativeFellow 13 — 4y
0
You're supposed to have a model in the workspace called 'Seats' with the seats in there. Only seats nothing else. User#31525 30 — 4y
0
@hexwulf its telling me Occupant is not a valid member of UnionOperation AdministrativeFellow 13 — 4y
0
@hexwulf all of my seats are unions that are inside of a model, I don't know if that explains anything AdministrativeFellow 13 — 4y
View all comments (2 more)
0
Try it now, i've applied a method for this issue of yours on the script. User#31525 30 — 4y
0
@hexwulf ah thank you so much, this worked perfectly. I appreciate the effort and time you put. Thanks again! AdministrativeFellow 13 — 4y
Ad
Log in to vote
1
Answered by
Lakodex 711 Moderation Voter
4 years ago

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 
0
Yes it worked thank you so much! AdministrativeFellow 13 — 4y
0
This wouldn't work when another player joins. Refer to my script below. User#31525 30 — 4y
0
you are right, this didn't work for multiple players AdministrativeFellow 13 — 4y
0
hexwulf Stop attempting to get credit. I have just tried this with my alt and it has teleported both of us sucessfully. Attemping to wind people in to getting accepted is actually against the rules Lakodex 711 — 4y
View all comments (2 more)
0
Did you read what I said? It wouldn't work when another player joins, only for the current players in the current server. In Administrative's post he said that he wanted to make it have a player sit when a player joined, however your 'code' with minor edits didn't provide that. User#31525 30 — 4y
0
Oh I see. I'm very sorry friend Lakodex 711 — 4y

Answer this question