Can somenoe help me with my script

Hi! How can I make it so only Staff team can go to the and Economy, Business, Comfort can’t go inside the door

script.Parent.Touched:Connect(function(hit)
	local Plr = game.Players:GetPlayerFromCharacter(hit.Parent)

	if Plr then
		if Plr.Team == game.Teams.Staff then
			script.Parent.CanCollide = false
		end
	end
end)
2 Likes
game.Players:GetPlayerFromCharacter(hit.Parent)

Always use game:GetService, in this case game:GetService(“Players”)

For your script, can you specify what do you mean by “only Staff team can go to the and Economy, Business, Comfort can’t go inside the door”? Staff cannot enter economy, business and comfort or can?

1 Like

You can assign them to a Collision Group. You can create a new group from the Collision Groups editor (Model > Collision Groups), create a new group, and set it so the group cannot collide with itself.

If you want the group to collide with other staff, but not the door, you have to make another collision group for just the door as well.

-- This can be put into ServerScriptStorage, since it's probably better to have this script only happen once
local PlayerService = game:GetService("Players")
PlayerService.PlayerAdded:Connect(function(player: Player)
	-- Check if they're staff here...
	player.CharacterAdded:Wait()
	local Character = player.Character
	for _, Descendant in Character:GetDescendants() do
		if not Descendant:IsA("Part") then continue end
		Descendant.CollisionGroup = "Admin"
	end
end)
-- The door itself doesn't need a script now, but here's the code if you'd like anyways
script.Parent.CollisionGroup = "AdminDoor"
2 Likes

Are those two different collision groups intentional? “Admin”, “AdminDoor”?

If they want Admins to collide with themselves but not the door, yes. If they don’t care if Admins want to collide with themselves, then no.

This is the Collision Group editor, you can create your own collision groups and set which groups can collide with others.
image

2 Likes

Oh dang! Never knew that you that you could pull a collision groups editor! Thanks!

2 Likes

If im correct, this should be a server script. You would need to send information using a remote event to that player, so it only turns off CanCollide for him. The remote event should be fired to a local script which should be located in StarterGUI, StarterCharacterScripts or StarterPlayerScripts.