Can somenoe tell me why my script is not working

it’s staff only door there’s 4 teams business,comfort,economy,staff but the door doesn’t seem to work (it’s only for staff) and it’s a model and there’s a localscript inside it the localscript doesn’t have a name.

local player = game.Players.LocalPlayer
local teams = game:GetService("teams")
local TeamDoor = game.Workspace:FindFirstChild("TeamDoor")
if player.Team == teams.Business or teams["Comfort"] then
	TeamDoor.CanCollide = false
end

4 Likes
  1. LocalScripts don’t run in Workspace
  2. Your script only checks the player’s team once. This is done way too early, so it’s likely that the player’s team hasn’t been set yet. Because this check is only made once, changes to a player’s team will not update their collision status with the door
4 Likes

Can you help me fix it? I’m beginner sorry

3 Likes

put the localscript inside of PlayerGui and add this code instead:

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = game.Workspace:WaitForChild("TeamDoor")

function updateDoor()
	--if you want either team to make the door open?
	TeamDoor.CanCollide = (player.Team == teams.Business or player.Team == teams.Comfort)
end

player.Changed:connect(function(change)
	if change ~= "TeamColor" then return end
	updateDoor()
end)

updateDoor()

hope this works and hope this helps?

4 Likes

it doesn’t work i can’t go thru the door

4 Likes

i placed it into startergui extraextra

3 Likes

ok try this script, I made a few changes to fix

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = game.Workspace:WaitForChild("TeamDoor")

function updateDoor()
	--if you want either team to make the door open?
	TeamDoor.CanCollide = not (player.Team == teams.Business or player.Team == teams.Comfort)
end

player.Changed:connect(function(change)
	warn(change)
	if change ~= "TeamColor" then return end
	updateDoor()
end)

updateDoor()
5 Likes

Use this instead:

player:GetPropertyChangedSignal("Team"):Connect(updateDoor)
5 Likes

where do i add it
esttexbutdfhhtddgg

3 Likes

woah taught me something thx. And Dennis you add it like this:

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = game.Workspace:WaitForChild("TeamDoor")

function updateDoor()
	--if you want either team to make the door open?
	TeamDoor.CanCollide = not (player.Team == teams.Business or player.Team == teams.Comfort)
end

player:GetPropertyChangedSignal("Team"):Connect(updateDoor)

updateDoor()

This should be your script. Is it working?

4 Likes

it’s a script or a localscript?

3 Likes

i placed it into startergui and it didnt work

3 Likes

CanCollide is not a valid member of Model “Workspace.TeamDoor” - Client - LocalScript:7

3 Likes
local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = workspace:FindFirstChild("TeamDoor")

local function ChangeCollisionProperty()
	for _,part in TeamDoor:GetChildren() do
		if part:IsA("BasePart") then
			TeamDoor.CanCollide = player.Team ~= teams.Business
		end
	end
end)
ChangeCollisionProperty()
player:GetPropertyChangedSignal("Team"):Connect(ChangeCollisionProperty)

Try this.

As you’re a beginner, I expect you’d ask: “Where to put the script?”

Okay so, insert a local script in StarterPlayer → StarterCharacterScripts and paste this script in that newly created script.

3 Likes

still doesnt’t work :frowning:
image

3 Likes
local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = workspace:FindFirstChild("TeamDoor")

local function ChangeCollisionProperty()
	for _,part in TeamDoor:GetDescendants() do
		if part:IsA("BasePart") then
			TeamDoor.CanCollide = player.Team ~= teams.Business
		end
	end
end)
ChangeCollisionProperty()
player:GetPropertyChangedSignal("Team"):Connect(ChangeCollisionProperty)
3 Likes

still doesn’t work

the output

3 Likes

image

3 Likes

Uhm not to be rude or anything but can you read properly?

READ THIS AND DO WHAT I SAID.

Also an updated script:

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
local TeamDoor = workspace:FindFirstChild("TeamDoor")

local function ChangeCollisionProperty()
	for _,part in TeamDoor:GetDescendants() do
		if part:IsA("BasePart") then
			TeamDoor.CanCollide = player.Team ~= teams.Business
		end
	end
end
ChangeCollisionProperty()
player:GetPropertyChangedSignal("Team"):Connect(ChangeCollisionProperty)
4 Likes

still doesn’t work. (extra letters)

3 Likes