Hi, I want to make a game where you need to collect these tokens, when you have enough tokens, you get to go further through the game, how can I make sure I have a door that only works for the people that have collected enough tokens?
✓ ANSWER ACCEPTED
How to make a part's cancollide be false for one player when they have collected enough of points?
2 answers
✓ Accepted answer
You can use CollisionFiltering
Server script: (place in workspace)
local PhysicsService = game:GetService("PhysicsService")
local doorGroup = "doorGroup"
local accessGroup = "accessGroup"
--you can only create a collision group once. If it already exists it will return a error
PhysicsService:CreateCollisionGroup(doorGroup)
PhysicsService:CreateCollisionGroup(accessGroup)
PhysicsService:CollisionGroupSetCollidable(doorGroup, accessGroup, false) -- makes the two groups uncollidable with eachother
Place this script inside the door:
local Players = game:GetService('Players')
local PhysicsService = game:GetService('PhysicsService')
local AccessList = {}
local Door = script.Parent
local RequiredTokens = 10
PhysicsService:CreateCollisionGroup(Door, "doorGroup") -- set the Door's group
function TOUCHED(hit)
if hit then
if Players:FindFirstChild(hit.Parent.Name) then
local player = Players:FindFirstChild(hit.Parent.Name)
local Tokens = player:FindFirstChild("leaderstats').Tokens -- replace
if not CHECK_LIST(player.Name) and (Tokens.Value >= 10) then
local character = player.Character
ACCESS(character)
end
end
end
function ACCESS(character)
if character then
for _, v in pairs(character:GetChildren()) do
if v:IsA('BasePart') then
PhysicsService:SetPartCollisionGroup(v, "accessGroup")
table.insert(AccessList, character.Name) -- add player to access group
end
end
end
end
function CHECK_LIST(playerName) -- checks if the player is in the access list/not
for i = 1, #AccessList do
if (playerName == AccessList[i]) then
return true
else
return false
end
end
end
Door.Touched:connect(TOUCHED)
2 comments
0
A few errors cause of some little mistakes but it should work, thanks.
num = -- Specified number of maximum points
plr = game.Players:GetPlayerFromCharacter(script.Parent)
stats = plr:FindFirstChild("leaderstats") -- Find the leaderboard
points = stats:FindFirstChild("Points") -- Find the Points value
debounce = true
script.Parent.Touched:Connect(function()
debounce = false
if plr then
if stats and points then
if points.Value == num then -- If maximum is reached...
script.Parent.CanCollide = false -- Turn CanCollide off
end
end
end
wait(1)
debounce = true
end)
5 comments
0
Why aren't you using any local variables? And if its a LocalScript, why not just use LocalPlayer? And if its a serverscript... then its very bad
0
Not a fan of local variables. I use variables based on raw Lua code.
0
If it works, I'll take it, thanks.
0
oof i made a answer but you posted yours first ):
0
lol
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
If your game is FE, you can simply set CanCollide to false from a LocalScript. Otherwise you need to use Collision Groups