I get errors when I touch the AccessDoor such as.

MarketplaceService:getProductInfo() failed because HTTP 400

And How do I go about Making sure it detect the Player wearing the T-Shirt and not just checking if they own it Because It would make it additional Security for players to require wearing these ticket t-shirts.

Any help on how may i achieve this would be wonderful.

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

-----------------
--| Variables |--
-----------------

local MarketplaceService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')

local VipDoor = workspace:FindFirstChild("AccessDoor")

local TShirtPass = {
	412190013, --Priority Class
	412190048, --First Class
	4934539728, --Plat
	218874232, --Gold
	218878415, --Silver
}

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- Finds out which side the player is on and teleports them to the other
local function TeleportToOtherSide(character, hitPart)
	local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
	local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
	local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3

	local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
	local distanceToBack = (behindDoor - hitPart.Position).magnitude
	if distanceToFront < distanceToBack then
		character:MoveTo(behindDoor)
	else
		character:MoveTo(inFrontOfDoor)
	end
end

-- When a player with the game pass touches the door, teleport them to the other side
local function OnTouched(otherPart)
	if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
		local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
		if player and not JustTouched[player] then
			JustTouched[player] = time()
			if MarketplaceService:PlayerOwnsAsset(player, #TShirtPass) then
				TeleportToOtherSide(player.Character, otherPart)
			end
		end
	end
end

-- Removes old entries in JustTouched
local function RemoveOldTouches()
	for player, touchTime in pairs(JustTouched) do
		if time() > touchTime + 0.3 then
			JustTouched[player] = nil
		end
	end
end

--------------------
--| Script Logic |--
--------------------

VipDoor.Touched:connect(OnTouched)

while true do
	RemoveOldTouches()
	wait(1/30)
end

1 comment

0

Why not check if the player's character has a ShirtGraphic (t-shirt) with a certain ID?