Hello there!
Im trying to make a player only door and after some basic search i got something out a tutorial but then i figured it was kinda outdated and some errors cameup.
Im pretty new at scripting so cant really brain it by myself.
SetPartCollisionGroup is deprecated, please use BasePart.CollisionGroup instead. More info: Updates to Collision Groups
how can i fix this error?
-- Roblox services
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local npcModel = script.Parent
-- the name of the group rather than referencing the group itself, so saving these
local playerGroup = "Players"
local npcGroup = "NPCs"
-- Create the collision groups and set them to not collide with each other
local function collisionGroupExists(groupName)
local groups = PhysicsService:GetRegisteredCollisionGroups()
for _, group in ipairs(groups) do
if group.name == groupName then
return true
end
end
return false
end
if not collisionGroupExists(npcGroup) then
PhysicsService:CreateCollisionGroup(npcGroup)
end
if not collisionGroupExists(playerGroup) then
PhysicsService:CreateCollisionGroup(playerGroup)
end
PhysicsService:CollisionGroupSetCollidable(npcGroup, playerGroup, false)
-- Helper function to recursively set the collision group on an object and all of
-- its children
local function setCollisionGroupRecursive(object, group)
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, group)
end
for _, child in ipairs(object:GetChildren()) do
setCollisionGroupRecursive(child, object)
end
end
-- Function called when a player character joins the game
local function onCharacterAdded(character)
-- Put all of the current parts of the model into the player collision group
setCollisionGroupRecursive(character, playerGroup)
-- Put any part that gets added to the character later into the collision group
character.DescendantAdded:Connect(function(descendant)
if descendant:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(descendant, playerGroup)
end
end)
end
-- Function called when a player joins the game
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
-- Sets the collision group of Blue to the npc group
setCollisionGroupRecursive(npcModel, npcGroup)
-- Bind PlayerAdded event to onPlayerAdded
Players.PlayerAdded:Connect(onPlayerAdded)
-- Make sure to add any characters that are currently in the game
-- to the collision group (otherwise the above event wouldn't catch
-- them
for _, player in ipairs(Players:GetPlayers()) do
onPlayerAdded(player)
end