Hey there! I’m trying to make a portal that you can enter if you have a certain badge, but it’s not destroying the part that’s blocking the portal whenever you push against the door and have the badge!
I’ve look over devforum and tried multiple ways but can’t figure it out!
Thanks for your help.
script:
script.Parent.Touched:Connect(function(hit)
local badgeservice = game:GetService("BadgeService")
local id = 2128141848
if hit and hit.Parent and hit.Parent.Humanoid then
if badgeservice:UserHasBadgeAsync(game.Players:GetPlayerFromCharacter(hit.Parent).UserId,id) then
game:GetService("ReplicatedStorage").destorybadgedoor:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
print("byebye")
else
print("uhoh no badge")
end
end
end)
I can’t check rn, but maybe :UserHasBadgeAsync uses a cache
if it does, you should check if they have the badge as they join and save it in a table, then, if you award a badge ingame, adjust the value for that player in the table
Try changing your script to this and tell me if it works:
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeService = game:GetService("BadgeService")
--//Variables
local RemoteEvent = ReplicatedStorage.destorybadgedoor
local Part = script.Parent
--//Controls
local BadgeId = 2128141848
--//Functions
local function HasBadge(player)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, BadgeId)
end)
if not success then
return false
end
end
Part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player then
if HasBadge(Player) then
RemoteEvent:FireClient(Player)
print("byebye")
else
print("uhoh no badge")
end
end
end)