Badge door wont work

Hello. I was trying to rescript a broken badge door. When I go and try to test it, it wont work.
Script:

local badgeID = 2113630409
local badgeservice = game:GetService("BadgeService")

function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if badgeservice:UserHasBadgeAsync(p.UserId, badgeID) then
				return -- ignore, this is for the button that opens the door
			elseif badgeservice:UserHasBadgeAsync(p.UserId, badgeID) == false then
				hit.Parent.Humanoid.Health = 0
			end
		end
	end
end

Oh yea no output and Iā€™m running this on a ServerScript.

Okay, so. The variable p is undefined.
You call the player player, but then start calling it p.

For better debugging, I suggest you add print statements inside of the if statements to see what is executing.
Also, the elseif statement is redundant. It use just be else.

Try this, it might work (this is sloppy and quick).

local badgeID = 2113630409
local badgeservice = game:GetService("BadgeService")

local part = -- your part

local function detect(p)
pcall(function()
if badgeservice:UserHasBadgeAsync(p.UserId, badgeID) then
-- if player has badge
else
-- set humanoid health to 0
end
end)
end

part.Touched:Connect(function(hit)
if hit.Parent.Name == plr.Name then
local plrs = game:GetService("Players").GetPlayerFromCharacter(hit.Parent)
if detect(plrs) then
part.CanCollide = false
end
end
end)

Change p.UserId to player.UserId

You forgot to actually attach the function to an event:
script.Parent.Touched:Connect(onTouched)

try this script!

local badgeID = 2113630409
local badgeservice = game:GetService("BadgeService")

function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if badgeservice:UserHasBadgeAsync(player.UserId, badgeID) then
				return -- ignore, this is for the button that opens the door
			elseif badgeservice:UserHasBadgeAsync(player.UserId, badgeID) == false then
				hit.Parent.Humanoid.Health = 0
			end
		end
	end
end
script.Parent.Touched:Connect(onTouched)

I AM SURE THIS WILL WORK!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.