Hello Scripters,
My friend is a very inexperienced scripter and wanted to create a badge door, or a door that would only let you passed if you own a badge. Because he’s in experienced he’s using two year old tutorials and nothing is working, he also can’t use the DevForum so I’m saying this on his behalf. The code is shown below.
local Player = game.Players.LocalPlayer
local BadgeService = game:GetService("BadgeService")
local BadgeTable = {
{
Door = game.Workspace.Door,
BadgeId = 00000000000
}
}
for LoopNum, Badge in pairs (BadgeTable) do
if BadgeService:UserHasBadgeAsync(Player.UserId,Badge.BadgeId) then
Badge.Door.CanCollide = false
end
end
The door, without the badge isn’t able to be gone through and even with the badge you can’t go through it. How can this be changed?
I’m not sure why he is using a table here, it’s quite weird to use a table for a badge, now let me get this right, your goal is to make the door open/Collision off when someone with a badge hits the door. Another question, is the full code because I don’t really see any touch functions or anything.
This works. All you have to do is go to StarterPlayer → StarterPlayerScripts click the ‘+’ and add a localscript and paste this code into the localscript (Works for me) make sure to actually put a badgeId you own to test it.
(Explination for my answer to help your friend understand)
Basiaclly a localscript is Client sided which means Player.
Script is server sides which means game.
If you need to access player data then try to use localscripts (In starterGui if UI, PlayerScripts if for Player Data & CharacterScripts if for the Character)
Make sure that you dont try to access thing like LocalPlayer as the game doesnt know which player that means. There is ONE client per person (ie. it knows who its user is) but one server for (exaple) 27 clients which means there are 27 localplayers.
(Please keep in mind that bc thiss is local script that the Door will only be Non-Collide for that player only) Which is what you wanted im pretty sure.
It’s not for a game he’s making, he wanted it for a small challenge for friends. So the current script is secure enough. And you could also just clip through the door.