Hello! My name is Koala_Helper, I am trying to make a level door that doesn’t open up for everyone, because when it does, there is a glitch that allows other players to let other players that don’t have the required amount of points to enter, and it let’s them in, does anybody know how to improve this script so I can fix that issue?
--
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
end
Door = script.Parent
function onTouched(hit)
print("Door Hit")
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
-- a human has touched this door!
print("Human touched door")
-- test the human's name against the leaderboard
local player = getPlayer(human)
if (player == nil) then return end
local stats = player:findFirstChild("leaderstats")
local sp = stats:findFirstChild("Points")
if sp == nil then return false end
if (sp.Value >= 150) then
print("Human passed test")
Door.Transparency = 1
Door.CanCollide = false
wait(5)
Door.CanCollide = true
Door.Transparency = 1
else Door.Transparency = 0.33
end
end
end
connection = Door.Touched:connect(onTouched)
You’ll want to use either a collisiongroup or a nocollision constraint. With a collision group, you can set two groups for players: Normal and VIP (or whatever). Also have a group for the door.
When a player respawns, set their collisiongroup of their character to Normal
When a player is allowed to access that door, set all parts of their character to the collision group VIP.
Collision groups allow parts to collide with parts of one group, and not of another. You can make parts in the DOOR and VIP group not collide, but DOOR and NORMAL collide. This means a VIP person can enter, but a NORMAL person will simply walk into it as if it was a wall.
As you can see in this table, players in the NormalPlayers group will collide with parts in the VIPDoor group, but players in the VIPPlayers group won’t.
There is plenty of documentation on collision groups and how to use them, for example Collision Filtering
If you use a nocollision constraint, you can do away with collision groups as you may need to use them elsewhere. Just set the Part0 of it to the player and the Part1 to the door, and they wont collide.
For an even simpler approach, just do the script on the client side as changes made by the client won’t replicate to other players. You can walk through but they wont.
its not too difficult once you understand it. It’s just a table where you say if something will or wont collide, and then just put parts into the spaces in the table.
Okay. I will try my best to do it, because I’m not that good at coding, all I do that helps me code is watch youtube videos. I want to be able to code some day without having to watch youtube videos to understand it.
thats perfectly fine. I learned how to code by basically copying other people’s code and altering it and after a while I can just write my own stuff no problem I started out not even knowing how a print statement worked