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?
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)
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)