How would i make a teleporter require a badge?

i want to have a teleporter to a different game that requires a badge for the teleporter to work for the player.

im a terrible scripter and usualy just search up how to do these types of things.

I have looked every where on the dev forum even on google and youtube but it looks like nobody has talked about how to do this yet.

this is the current script im using for the normal teleporters.

local gameID =  #######
	function onTouched(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
		TeleportService:Teleport(gameID, player)
	end
	end

script.Parent.Touched:connect(onTouched)

3 Likes

Try this

local gameID =  "ID_HERE"
local TeleportService = game:GetService("TeleportService")
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local badgeId = 2125638306 


function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local success, result = pcall(userHasBadge, badges, player.UserId, badgeId) 
			if success then
				TeleportService:Teleport(gameID, player)
			end
		end
	end
end

script.Parent.Touched:connect(onTouched)
1 Like

i just tried this and it teleports you even if you don’t own the badge?

I think I make a small typo, try this :

local gameID =  "ID_HERE"
local TeleportService = game:GetService("TeleportService")
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local badgeId = 2125638306 


function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local success, result = pcall(userHasBadge, badges, player.UserId, badgeId) 
			if success then
                if result then
			       	TeleportService:Teleport(gameID, player)
                end
			end
		end
	end
end

script.Parent.Touched:connect(onTouched)
4 Likes