Script works in Studio But not ingame

This TeamDoor Script I’ve got works within studio but not ingame

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local doorCollisionGroup = "GroupDoor"
local targetTeams = {"Grand Chancellor", "Patron", "Imperial Patron", "Executive Director"} -- Add more team names as needed

-- Ensure the door collision group exists and configure its collision rules
PhysicsService:RegisterCollisionGroup(doorCollisionGroup)
PhysicsService:CollisionGroupSetCollidable(doorCollisionGroup, doorCollisionGroup, false)

-- Set the collision group for the door parts (replace "GroupDoor" with your actual door part name)
for _, part in ipairs(workspace.GroupDoor:GetDescendants()) do
	if part:IsA("BasePart") then
		part.CollisionGroup = doorCollisionGroup
	end
end

local function setCollisionGroupForCharacter(character, group)
	for _, part in ipairs(character:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CollisionGroup = group
		end
	end
end

local function isInTargetTeams(teamName)
	for _, targetTeam in ipairs(targetTeams) do
		if teamName == targetTeam then
			return true
		end
	end
	return false
end

local function onCharacterAdded(player, character)
	local team = player.Team
	if team and isInTargetTeams(team.Name) then
		setCollisionGroupForCharacter(character, doorCollisionGroup)
	else
		setCollisionGroupForCharacter(character, "Default")
	end
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("HumanoidRootPart")
		onCharacterAdded(player, character)
	end)

	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Character then
			onCharacterAdded(player, player.Character)
		end
	end)

	if player.Character then
		onCharacterAdded(player, player.Character)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

-- Handle players who are already in the game
for _, player in ipairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

No errors in output, A little stumped

Are you perhaps in Team Create? You may just have forgotten to commit the Script changes.

Are you sure you published your changes in studio to Roblox?

Team create isn’t on and all changes have been published, Still not working

How about using .CharacterAppearanceLoaded to wait for the character to load? It may just be because the character loads quicker in Studio or something.

1 Like

I’ll give it a go, See if it works

That fixed the issue, Thank you :pray:

1 Like