Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

5 comments

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.

0

Quite alright Sir! I'll go try this anyway.

0

This didn't work, could be my fault though.

0

Have you used manual weld or this a normal roblox-generated seat?

0

Roblox generated seat.

1 answer

✓ Accepted answer

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

3 comments

0

Oh, Let me try this, Thanks!

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?

0

Hi! it's been a year and I've improved greatly. I see what you mean mate. Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.