So I have a part that once you touch you teleport to another world, I used this script for it:
local TeleportService = game:GetService("TeleportService")
local placeID = 8951064375
local function onPartTouch(otherPart) local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) if player then TeleportService:Teleport(placeID,player) end end
So, I'm trying to make another teleporter where if you touch the part you also get teleported to another world, but first, you need to own some specific badges from the game to be able to teleport, how can I make it work?
Also, please explain thoroughly as I'm a very new and bad scripter lol.
For that you can use BadgeService:UserHasBadgeAsync()
First we need 2 parameters, the player user id and the badge id. We will be also using pcall()
If we have both of them we can do following:
local BadgeService = game:GetService("BadgeService") -- Get service local TeleportService = game:GetService("TeleportService") local function onPartTouch(otherPart) local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) local BadgeID = 0000000 -- Change this to your badge ID local placeID = 8951064375 if player then local success, hasBadge = pcall(function() -- Run a pcall() to check if the user has badge or not. return BadgeService:UserHasBadgeAsync(player.UserId, BadgeID) -- check if user has badge and return either true or false end) if not success then -- check if it was not successful warn("Operation was not successful!") -- print a warning that it was not successful end if hasBadge then -- If the user has the badge TeleportService:Teleport(placeID,player) -- Teleport end end end
If you have any questions, feel free to ask me! Make sure to mark this as answer if this was helpful.
-- If you want to check for multiple badges, you can do following: local success, hasBadge = pcall(function() return BadgeService:UserHasBadgeAsync(player.UserId, BadgeID) and BadgeService:UserHasBadgeAsync(player.UserId, BadgeID_2) and BadgeService:UserHasBadgeAsync(player.UserId, BadgeID_3) -- And so on... end)