Question with a Script

Hello, Ive just generated a script for one of my games using Bing AI.
I want to see if its good enough to put in my game or if its broken.
The purpose of the script is to make a specific team only be allowed to sit on a certain seat.

local seat = Instance.new(“Seat”)
seat.Anchored = true
seat.Position = Vector3.new(0, 1, 0)
seat.Parent = workspace

local redTeam = game.Teams:FindFirstChild(“RedTeam”) – Replace with your actual team name

local function OnChildAdded(Child)
if Child.Name == “SeatWeld” and Child:IsA(“Weld”) then
local Character = Child.Part1.Parent
local player = game.Players:GetPlayerFromCharacter(Character)

    if player and redTeam:IsPlayerInTeam(player) then
        wait(0.1)
        seat.Disabled = false -- Allow sitting
    else
        wait(0.1)
        seat.Disabled = true -- Disallow sitting
    end
end

end

seat.ChildAdded:Connect(OnChildAdded)

Hello! The following function does not actually exist in roblox, therefore the script is broken:
‘isPlayerInTeam()’

Is there a possible fix? Like changing it to something different?

You could change it to:
if (player and player.TeamColor == redTeam.TeamColor) then

Thanks for the help, Ill see if it works.

Yeah, using that should make it work.

Should it look something like this :

local seat = Instance.new(“Seat”)
seat.Anchored = true
seat.Position = Vector3.new(0, 1, 0)
seat.Parent = workspace

local redTeam = game.Teams:FindFirstChild(“RedTeam”) – Replace with your actual team name

local function OnChildAdded(Child)
if Child.Name == “SeatWeld” and Child:IsA(“Weld”) then
local Character = Child.Part1.Parent
local player = game.Players:GetPlayerFromCharacter(Character)

    if (player and player.TeamColor == redTeam.TeamColor) then
        wait(0.1)
        seat.Disabled = false -- Allow sitting
    else
        wait(0.1)
        seat.Disabled = true -- Disallow sitting
    end
end
end

seat.ChildAdded:Connect(OnChildAdded)

Try it out, that’s the best way to learn.

Okay so the issue with the script is i’m trying to put it in a already existing seat even tho it makes a new seat. Is there a way to fix this possibly?

Nevermind, I got it, thanks again for the help yesterday.

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