I have a fairly simple script where if a player has premium they can go through a part else they cannot.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
if player.MembershipType == Enum.MembershipType.Premium then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
Is this program written in a LocalScript object, or is it written in a Script object? It must be placed in the LocalScript object for it to work. Also, this script must be inside of the part.
If it’s a server script, you can’t get the player by doing LocalPlayer. Besides, you should make this a local script anyway, because if you don’t then the part will have CanCollide false for everyone.
you need to make it a local script. you can’t call localplayer over a normal server script. Also you can change the part properties through a local script if you are scared it won’t change through the client.
local PhysicsService = game:GetService("PhysicsService")
local premiumDoors = "PremiumDoors"
-- Create door collision groups
PhysicsService:CreateCollisionGroup(premiumDoors)
PhysicsService:SetPartCollisionGroup(workspace.PremiumDoor, premiumDoors)
local premiumPlayers = "PremiumPlayers"
-- Create player collision groups
PhysicsService:CreateCollisionGroup(premiumPlayers)
local function setCollisionGroup(character, groupName)
for _, child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(child, groupName)
end
end
character.DescendantAdded:Connect(function(descendant)
if descendant:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(descendant, groupName)
end
end)
end
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
if player.MembershipType == Enum.MembershipType.Premium then
setCollisionGroup(character, premiumPlayers)
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
PhysicsService:CollisionGroupSetCollidable(premiumDoors, premiumPlayers, false)