#i was trying to make a badge door then it doesnt work when i checked console it showed this
1 messages · Page 1 of 1 (latest)
Can you provide the relevant code?
yeah wait
On the documentation for UserHasBadgeAsync, it recommends you wrap it in a pcall incase the request fails. https://create.roblox.com/docs/reference/engine/classes/BadgeService#UserHasBadgeAsync
since I'm bad at scripting
I need help
I'm gonna show the code rn wait
Studio is installing
Okay
It’s probably being rate limited because the touched event fires alot
i dont know
First, try giving it a cooldown
Also, you can just write else instead of elseif this == false, because the else statement will run if the first value is false anyways.
k ill try it
How did you go about adding a cooldown?
i gave it 1 second
now idk what to do
heres the file btw
** You are now Level 4! **
Now that you have a cooldown it won't be spamming requests, and you can test that by adding a print into the Touched function.
To make sure you always get a response on UserHasBadgeAsync, replace if badgeservice:UserHasBadgeAsync(p.UserId, badgeholder) with
local success, hasBadge
while not success do
success, hasBadge = pcall(function()
return badgeservice:UserHasBadgeAsync(p.UserId, badgeholder)
end)
task.wait(.1)
end
if hasBadge then
... -- Has the badge
else
... -- Doesn't have the badge
end
k i jus tadded it in
i need to wait for it to load
it keeps showing me white
like
white character
etc
@gray holly
badgeasync now shows to many requests
@gray holly
You don't need to ping me twice 
k
Did you adjust your code with that and a cooldown?
what's the code looking like now
uh
Don't just mindlessly copy&paste the code in, adjust it with those changes. Put the code to open the door in the top of the if hasBadge statement, and the hit.Parent.Humanoid.Health = 0 at the bottom.
where it currently says "has the badge" and "doesnt have the badge", just replace those
uh
could you just try to fix the code
except for doing this more complicated?
@gray holly
can you paste it here, I can't be bothered re-typing all that
k
door = script.Parent
badgeholder = door.Parent.BadgeID.Value
local badgeservice = game:GetService("BadgeService")
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local success, hasBadge
while not success do
success, hasBadge = pcall(function()
return badgeservice:UserHasBadgeAsync(p.UserId, badgeholder)
end)
task.wait(.1)
end
if hasBadge then
... -- Has the badge
else
... -- Doesn't have the badge
end
door.Transparency = 0.8
door.CanCollide = false
wait(1)
door.Transparency = 0.5
door.CanCollide = true
elseif badgeservice:UserHasBadgeAsync(p.UserId, badgeholder) == false then
hit.Parent.Humanoid.Health = 0
end
end
end
end
door.Touched:connect(onTouched)
door = script.Parent
badgeholder = door.Parent.BadgeID.Value
local badgeservice = game:GetService("BadgeService")
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local success, hasBadge
while not success do
success, hasBadge = pcall(function()
return badgeservice:UserHasBadgeAsync(p.UserId, badgeholder)
end)
task.wait(.1)
end
if hasBadge then
-- Open the door
door.Transparency = 0.8
door.CanCollide = false
wait(1)
door.Transparency = 0.5
door.CanCollide = true
else
-- Kill the player
hit.Parent.Humanoid.Health = 0
end
end
end
end
door.Touched:connect(onTouched)
** You are now Level 4! **
I'd rather actually teach you what went wrong so you can fix any issues that you have in the future, but this is what you need to do.
just remove the else and the code after it
k
Like
if hasBadge then
-- Open the door
door.Transparency = 0.8
door.CanCollide = false
wait(1)
door.Transparency = 0.5
door.CanCollide = true
end
You should learn how if-statements work though, it's a fundamental part of programming in any language.
Yeah, exactly!
now lets wait for it to load
And add a cooldown, I forgot about that but you need it because there is a limit to using :UserHasBadgeAsync
isnt wait (1) the cooldown
No, I mean a cooldown on the whole thing running
where do i place the cooldown (i dont know scripting)
Add this 1 second cooldown. Make sure to add it to the code from before, not replace it.
local cooldown = false
function onTouched(hit)
if cooldown then return end
task.delay(1,function() cooldown = false end)
end
wait
** You are now Level 5! **
i just tried uh
the door
it worked nad then it stopped
im gonna add the cooldown rn
but
could you add it to this script (im sorry if im wasting your time)
door = script.Parent
badgeholder = door.Parent.BadgeID.Value
local badgeservice = game:GetService("BadgeService")
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local success, hasBadge
while not success do
success, hasBadge = pcall(function()
return badgeservice:UserHasBadgeAsync(p.UserId, badgeholder)
end)
task.wait(.1)
end
if hasBadge then
-- Open the door
door.Transparency = 0.8
door.CanCollide = false
wait(1)
door.Transparency = 0.5
door.CanCollide = true
else
-- Kill the player
hit.Parent.Humanoid.Health = 0
end
end
end
end
door.Touched:connect(onTouched)
@gray holly
door = script.Parent
badgeholder = door.Parent.BadgeID.Value
local badgeservice = game:GetService("BadgeService")
local cooldown = false -- Add the cooldown bool outside the onTouched function
function onTouched(hit)
if cooldown then return end -- Don't run if it's on cooldown
cooldown = true -- Turn on cooldown
task.delay(1,function() cooldown = false end) -- Reset cooldown after 1 second
if hit.Parent:FindFirstChild("Humanoid") then
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
local success, hasBadge
while not success do
success, hasBadge = pcall(function()
return badgeservice:UserHasBadgeAsync(p.UserId, badgeholder)
end)
task.wait(.1)
end
if hasBadge then
-- Open the door
door.Transparency = 0.8
door.CanCollide = false
wait(1)
door.Transparency = 0.5
door.CanCollide = true
else
-- Kill the player
hit.Parent.Humanoid.Health = 0
end
end
end
end
door.Touched:connect(onTouched)
Try to understand what I change, so you can learn to do it yourself.
If you want to learn Roblox scripting, there are many great tutorials/series on YouTube, which is a great place to start (especially for basic things like if statements, variables, etc.)
but
i have like
more badge doors
should i delete them
to see if it works
@gray holly
In todays video I show you how to make a badge only door in Roblox Studio. I Hope you enjoyed the video, Have a lovely rest of your day! If you are a bit confused what to do, Feel free to create a ticket in my discord server and we can help you out!
Script (LocalScript in StarterPlayerScripts) :
local BadgeID = 1234567890 -- Replace with your ...
and console says there are many uh
badgeasync requests
@gray holly
That's different, try following that 1:1 instead.