Get player to change teams when they sit down in a seat

I am trying to change the player’s team automatically when they sit down in a seat.

I have made a script but the player’s team is NOT changing when they sit down in this seat, and I am not sure what is wrong as I am mainly a builder not a coder.

This is my code:

local Team="Audience"
local Players = game:GetService("Players")
local seat = script.Parent

if seat.Occupant then
	local Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
	Player.Team = game:GetService("Teams")[Team]
end

If someone could help me understand what’s wrong I would be greatly appreciative.

When is this particular script ran?

You’ve almost got it :open_mouth:

According to the seat documentation, the seat has two properties: Disabled and Occupant. You can listen to a changed event (which is fired when someone sits / gets out of the seat, get the player, and change their team!

local Team = "Audience"
local Players = game:GetService("Players")
local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
	if Player then
		Player.Team = game:GetService("Teams")[Team]
	end
end)
3 Likes

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