Make a Part CanCollide = false locally if Badge is Owned

Hey developers,

I need help making a local script that makes it so if a player owns a badge then CanCollide = false on a part locally and if they don’t own the badge then CanCollide = true on a part locally. I tried a lot of different options and most of them don’t work. I’m still pretty new to scripting so if anyone can help I would very much appreciate it.

1 Like

You can check if a player has a badge with the BadgeService in a server script and then use a RemoteEvent to call a local script to disable the collision.

In the BadgeService documenation, you can use this script.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = {000000000} -- replace this with your badge id(s)
local part = game.workspace.Part -- Replace with your part
local function onPlayerAdded(player)
	-- Check if the player has any of the badges
	local success, result = pcall(function()
		return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
	end)
	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player", player.Name, "has badges:", result)
		return
	end

	local ownedBadgeIds = result

	if #ownedBadgeIds == 0 then
		print(player.Name, "does not have any of the badges")
	else
        part.CanCollide = false -- makes part CanCollide false
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

i probably shoulda clarified but yeah, you can use this in a local script and it should still work perfectly fine.

That would disable collision globally.

badgeservice works in localscripts btw

so just use that script and change it to a localscript and use WaitForChild for whatever ur trying to make invisible

1 Like