Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

4 comments

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.

0

To go about killing an avatar, call Humanoid:TaleDamage(Humanoid.Health) from and ‘else’ scope within the :UserOwnsBadge() conditional.

0

See my example here: https://pastebin.com/ShU4f5Yx.

0

The example didn't really seem to work.

2 answers

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

1 comment

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.

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


1 comment

0

^^ The "--//Code" Feahren had, correct me if I'm wrong.

This discussion is preserved as it was. New answers, comments, and votes are closed.