I want to make a shop that only certain players can enter. I know how to retrieve the data, but how can I make a part that is completely uncollideable to some players but can collide with others, thus blocking them?
You can do this by using PhysicsService. To do what you're trying to do, first you have to make the Collision group.
local physicsService=game:GetService("PhysicsService") local name = "parts" --// put this to whatever you want local collisionGroup = physicsService:CreateCollisionGroup(name);
Now that you have created it we have to set the part's collision group
local part = yourpart --// you have to set your part physicsService:SetPartCollisionGroup(part,name) --// the name
Perfect! Now we have setup the parts collision group, now we'll add the players collision group so we can set them non collidable
local pname = "players" --// you can also change this physicsService:CreateCollisionGroup(pname)
Now that we have the groups we'll start with a player added event so we can set the parts
local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) --// listens to every new player that joins player.CharacterAdded:Connect(function(character) --// listens to character added --// now here we add the parts to the collision group for i,v in pairs(character:GetDescendants()) do if v:IsA("BasePart") then physicsService:SetPartCollisionGroup(v,pname) --// basically what this does is add all the player's parts to the collision group end end --// now we'll listen for any part created character.DescendantAdded:Connect(function(descendant) if descendant:IsA("BasePart") then physicsService:SetPartCollisionGroup(descendant,pname) end end) end) end)
That's it! Now we just have to set them to not collide!
physicsService:CollisionGroupSetCollidable(name,pname,false) --// sets collission off
Done! You have created it! Now you just have to determine if the player has the permission to enter!
Final Code:
local part = yourpart --// you have to set your part physicsService:SetPartCollisionGroup(part,name) --// the name local pname = "players" --// you can also change this physicsService:CreateCollisionGroup(pname) local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) --// listens to every new player that joins player.CharacterAdded:Connect(function(character) --// listens to character added --// now here we add the parts to the collision group for i,v in pairs(character:GetDescendants()) do if v:IsA("BasePart") then physicsService:SetPartCollisionGroup(v,pname) --// basically what this does is add all the player's parts to the collision group end end --// now we'll listen for any part created character.DescendantAdded:Connect(function(descendant) if descendant:IsA("BasePart") then physicsService:SetPartCollisionGroup(descendant,pname) end end) end) end) physicsService:CollisionGroupSetCollidable(name,pname,false) --// sets collission off
Hope this helped :D if it did please accept it!
step one: make local script
step two: get the player in that local script (if you doing something like checking for a gamepass
step two and a half: get the part you want the player to go through
step three:
make an if
statement. set your criteria into the if
statement.
step four: in the if statement, make the part that the player is going
the script should look like:
local player=game.Players.LocalPlayer local door=set_the_door_here if set_your_criteria_here then door.CanCollide=true else door.CanCollide=false end
set_the_door_here
and set_your_criteria_here
. none of this will replicate to other players because it is made in a localscript.)FireClient() all of the clients that meet the requirement from the server. Then, in a localscript, make the part CanCollide off in an OnClientEvent, so this change will only be replicated to the clients who meet the requirements.