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

gloomy saffron
gray holly
gloomy saffron
#

yeah wait

gray holly
gloomy saffron
#

since I'm bad at scripting

#

I need help

#

I'm gonna show the code rn wait

#

Studio is installing

gray holly
#

Okay

gloomy saffron
#

@gray holly

#

@gray holly

gray holly
gloomy saffron
#

i dont know

gray holly
#

First, try giving it a cooldown

gloomy saffron
#

k

#

1 sec

#

k

#

nope

#

i gave it

#

its still the same

gray holly
#

Also, you can just write else instead of elseif this == false, because the else statement will run if the first value is false anyways.

gloomy saffron
#

k ill try it

gray holly
gloomy saffron
#

now idk what to do

marsh lilyBOT
#

studio** You are now Level 4! **studio

gray holly
#

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
gloomy saffron
#

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

gray holly
#

You don't need to ping me twice crying

gloomy saffron
#

k

gray holly
#

what's the code looking like now

gloomy saffron
#

here

#

@gray holly

gray holly
#

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

gloomy saffron
#

uh

#

could you just try to fix the code

#

except for doing this more complicated?

#

@gray holly

gray holly
gloomy saffron
#
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)
gray holly
#
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)
marsh lilyBOT
#

studio** You are now Level 4! **studio

gray holly
#

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.

gloomy saffron
#

wait

#

could you make it non killable?

gray holly
#

just remove the else and the code after it

gloomy saffron
#

k

gray holly
#

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.

gloomy saffron
#

i just removed this

#

else
-- Kill the player
hit.Parent.Humanoid.Health = 0

gray holly
#

Yeah, exactly!

gloomy saffron
#

now lets wait for it to load

gray holly
gloomy saffron
#

isnt wait (1) the cooldown

gray holly
#

No, I mean a cooldown on the whole thing running

gloomy saffron
#

where do i place the cooldown (i dont know scripting)

gray holly
#

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
gloomy saffron
#

wait

marsh lilyBOT
#

studio** You are now Level 5! **studio

gloomy saffron
#

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

gray holly
# gloomy saffron 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")
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.

gloomy saffron
#

alright

#

ill try it now

gray holly
#

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

gloomy saffron
#

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 ...

▶ Play video
#

and console says there are many uh

#

badgeasync requests

#

@gray holly

gray holly
gloomy saffron
#

alright

#

ill delete those doors

#

@gray holly

#

as i just saw

#

i deleted those scripts

#

and

#

itttt

#

works

#

tysm