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

Players not being inserted into table? Anyone got any ideas why this isn't working?

Asked by 6 years ago

So I'm going to explain with comments in my script..

I wrote a Server Script but a part of it doesn't seem to be working

local roundRunning = false
local Intermission = true

local seatOne = game.Workspace.Chair1.Seat
local seatTwo = game.Workspace.Chair2.Seat
local seatThree = game.Workspace.Chair3.Seat
local seatFour = game.Workspace.Chair4.Seat
local seatFive = game.Workspace.Chair5.Seat
local chairSix = game.Workspace.Chair6.Seat

if Intermission == true then
    local intermissionHint = Instance.new("Hint", workspace)
    for i = 30, 0, -1 do
        intermissionHint.Text = "Intermission: "..i
        wait(1)
        if i == 0 then
            wait(1)
            intermissionHint:Destroy()
            Intermission = false
            roundRunning = true
        end
    end
end

if roundRunning == true then
    for i,v in pairs(game.Players:GetPlayers()) do
        v.Character.HumanoidRootPart.CFrame = CFrame.new(25.61, 7.989, 11.08)
    end
    local playersInCurrentGame = {} -- This is a table of players in the current round, I'll work on this later
    local playersSeated = {} -- Players seated table THIS IS MY PROBLEM

    if seatOne:FindFirstChild("SeatWeld") then -- Here I'm checking for the seat weld that's created when players sit.
        RootPartOfPlayer = seatOne.SeatWeld.Part1 -- I'm defining the root part
        playerInThisSeat = game.Players:GetPlayerFromCharacter(seatOne.SeatWeld.Part1) -- Here defining the player in the seat
        table.insert(playersSeated, playerInThisSeat) -- Here inserting the player into this table
        for i,v in pairs(playersSeated) do
            print(playersSeated[i].Name) -- Here I'm trying to print who's in the seat (for testing purposes) but it's not printing anything if anyone could help me fix my mistake it would be appreciated
        end
    end


end
0
I'm not sure but I think you used the wrong thing at line 36? Sorry if this didn't do anything for you. Nep_Ryker 131 — 6y
0
Quite alright Sir! I'll go try this anyway. andyad13 74 — 6y
0
This didn't work, could be my fault though. andyad13 74 — 6y
0
Have you used manual weld or this a normal roblox-generated seat? tantec 305 — 6y
0
Roblox generated seat. andyad13 74 — 6y

1 answer

Log in to vote
1
Answered by
xAtom_ik 574 Moderation Voter
6 years ago

It is not working because on line 34, you use GetPlayerFromCharacter which takes the actual player model as the argument, not a part, so it will always return nil.

Source

0
Oh, Let me try this, Thanks! andyad13 74 — 6y
0
Hello Sir, thanks again for helping. So I changed the varriable "playerInThisSeat" to playerInThisSeat = game.Players:GetPlayerFromCharacter(seatOne.SeatWeld.Part1.Parent) But it still doesn't seem to be working :/ Have any ideas why? andyad13 74 — 6y
0
Hi! it's been a year and I've improved greatly. I see what you mean mate. Thanks andyad13 74 — 5y
Ad

Answer this question