Trying to assign player name to seat and plate

hello! i have a table with chairs and plates 1-20. when the player joins, a player will be sat in a seat and their name will be stored in the seat’s and plate’s attributes. storing the name in the seat works but not for the plate. i tried something but it didnt work. ty!

eg:
if a player joins and gets seat 1, their name will be stored in seat 1 and in plate 1.

script:

function startGameModule.startGameFunction()

	game.Players.PlayerAdded:Connect(function(p)
		wait(3)
		local c = p.Character
		local seatOFFSET=CFrame.new(0,2,0)

		local seatFolder = workspace.tableModel.seatFolder
		local plateFolder = workspace.tableModel.plateFolder
		local hum:Humanoid = c.Humanoid
		randomSeat = seatFolder:GetChildren()[math.random(1, #seatFolder:GetChildren())]
		randomPlate = plateFolder:GetChildren()[math.random(1, #plateFolder:GetChildren())]

		if randomSeat:GetAttribute("occupied") == false then
			c:PivotTo(randomSeat.CFrame* seatOFFSET) 
			wait()
			randomSeat:Sit(hum)
			if randomSeat.Occupant then
				randomSeat:SetAttribute("occupied", true)
				randomSeat:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
				randomPlate:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
				print(randomSeat.Name)
				print(randomPlate.Name)

	
			end
		end	
	end)
end

It’s because you’re using a new random number for the plate and the chair. You have to store a random number variable and then use it for both

1 Like

hey man,
thanks for ur response. :slight_smile:

i got it. absolutely perfect. tysm!

i got a bit of help from this post too

local randomSeat:Seat = nil
local randomPlate = nil
local randomNo = Random.new():NextInteger(1, 20)


function startGameModule.startGameFunction()

	game.Players.PlayerAdded:Connect(function(p)
		wait(3)
		local c = p.Character
		local seatOFFSET=CFrame.new(0,2,0)

		local seatFolder = workspace.tableModel.seatFolder
		local plateFolder = workspace.tableModel.plateFolder
		local hum:Humanoid = c.Humanoid
		randomSeat = seatFolder:GetChildren()[randomNo]
		randomPlate = plateFolder:GetChildren()[randomNo]

		if randomSeat:GetAttribute("occupied") == false then
			c:PivotTo(randomSeat.CFrame* seatOFFSET) 
			wait()
			randomSeat:Sit(hum)
			if randomSeat.Occupant then
				randomSeat:SetAttribute("occupied", true)
				randomSeat:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
				randomPlate:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
				print(randomSeat.Name)
				print(randomPlate.Name)

	
			end
		end	
	end)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.