:Destroy() Not working on a local script

Hey there! I’m trying to make a portal that you can enter if you have a certain badge, but it’s not destroying the part that’s blocking the portal whenever you push against the door and have the badge!
I’ve look over devforum and tried multiple ways but can’t figure it out!
Thanks for your help.
script:

script.Parent.Touched:Connect(function(hit)
	local badgeservice = game:GetService("BadgeService")
	local id = 2128141848
	
	if hit and hit.Parent and hit.Parent.Humanoid then
		if badgeservice:UserHasBadgeAsync(game.Players:GetPlayerFromCharacter(hit.Parent).UserId,id) then
			game:GetService("ReplicatedStorage").destorybadgedoor:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
			print("byebye")
		else
			print("uhoh no badge")
		end
	end
end)

local script:

game:GetService("ReplicatedStorage"):WaitForChild("destorybadgedoor").OnClientEvent:Connect(function(plr)
	print("destroying")
	script.Parent:Destroy()
	print("destroyed")
end)

what lines print?

I can’t check rn, but maybe :UserHasBadgeAsync uses a cache
if it does, you should check if they have the badge as they join and save it in a table, then, if you award a badge ingame, adjust the value for that player in the table

Try changing your script to this and tell me if it works:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeService = game:GetService("BadgeService")

--//Variables
local RemoteEvent = ReplicatedStorage.destorybadgedoor
local Part = script.Parent

--//Controls
local BadgeId = 2128141848

--//Functions
local function HasBadge(player)
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, BadgeId)
	end)

	if not success then
		return false
	end
end

Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	
	if Player then
		if HasBadge(Player) then
			RemoteEvent:FireClient(Player)
			
			print("byebye")
		else
			print("uhoh no badge")
		end
	end
end)

everything expect destory and destorying

nope does not work, i think i might be that the remote is not firing properly

it might be because of a caching behavior of UserHadBadgeAsync causing that if statement to fail and not fire the remote

Is there any errors or messages in the output?

no errors at all! So i’m kind of confused

@Katrist script change they made still didn’t work so i dont think its that.

no, that would still use the caching behavior

It would still print a message though if it failed. So I have no clue why this isn’t working.

wait yes, it says i dont have the badge but i do have the badge.

it wouldnt fail if it hit the cache

It would. When you use a pcall and the function warns, it counts it as an error and exits the pcall.

Ohhh, okay. Try the game not in studio and see if it works.

it wouldnt warn either from hitting the cache
hitting the cache is normal behavior

Try it yourself. It exits the pcall if it hits the API limit, which is intended behaviour.

still doesn’t work! (extra text so i can send the message)

nit:
image
warns don’t count as errors in pcalls

hitting the API limit is a separate issue
I said “cache”