Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a badge powered door that kills people who do not own the badge?

Asked by 4 years ago

You see, I wanted a way to make it so that if you own a specific badge, you can open a door. And if you don't own it, you are killed. I've been trying for ages, but I also have a question; can the door be part of a group?

0
If you’re creating a door, you will be using the .Touched event of the given Part you wish to assign interaction with. Allocate the Humanoid potentially found via Hit.Parent:FindFirstChildOfClass("Humanoid") into a variable, then uplink the Player the same way through Players:GetPlayerFromCharacter(Hit.Parent). You can then use these two to apply the code below. Ziffixture 6913 — 4y
0
To go about killing an avatar, call Humanoid:TaleDamage(Humanoid.Health) from and ‘else’ scope within the :UserOwnsBadge() conditional. Ziffixture 6913 — 4y
0
See my example here: https://pastebin.com/ShU4f5Yx. Ziffixture 6913 — 4y
0
The example didn't really seem to work. BudyGon 0 — 4y

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

You can use BadgeService’s :UserHasBadge() method to validate whether the given Player has the given Badge. This function return a Boolean value which means we can call it directly in a conditional.

local BadgeService = game:GetService("BadgeService")
local BadgeId = --// Badge Asset ID
local Player = game:GetService("Players").LocalPlayer

if (BadgeService:UserHasBadge(Player.UserId, BadgeId) then
    --// Code
end
0
Inside the --// code, let the player enter. Other's wont be able to enter due to the fact that it's local. Inside the if statement, add an else statement in which you specify whether the hit.Parent is a humanoid or not, then get their humanoid and kill them. AcrylixDev 119 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local door = workspace:WaitForiChild("") -- Insert the door's name here
local BadgeService = game:GetService("BadgeService")
local BadgeId -- = // Badge Asset Id 
local Player = game:GetService("Players").LocalPlayer
local debounce = false
local debounce2 = false

if  (BadgeService:UserHasBadge(Player.UserId, BadgeId)) then
    door.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
            debounce = true
            for i = 1,10,1 do
                door.Transparency = door.Transparency+(0.1)
            end
            wait()
            door.CanCollide = false
            wait(3)
            for i = 1,10,1 do
                door.Transparency = door.Transparency-(0.1)
            end
            wait()
            door.CanCollide = true
            debounce = false
        end
    end)
else
    door.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and debounce2 == false then
            debounce2 = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 100
            wait()
            debounce2 = false
        end
    end)
end


0
^^ The "--//Code" Feahren had, correct me if I'm wrong. AcrylixDev 119 — 4y

Answer this question