Why isnt this script working?

local PassId = 162973845
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, PassId) then

	wait()
		script.Parent.Glass.Anchored=false
		script.Parent.Glass.Velocity=Vector3.new(0,0,50)
		script.Parent.Parent.CoverRemoved.Value=true
		script:Destroy()

	end
	end)

wont work must help needed

What happens right now when you click the click detector? Any errors? It doesn’t run?

Edit: Also is this in a local script? Server script? and where is the script located?

Either you do not own the GamePass or it’s not detecting the “ClickDetector” try

script.Parent:WaitForChild('ClickDetector'):Connect(function(plr)

end)

As it may take time to load

1 Like

Hey, there is an issue with your code where the wait() function is blocking the code from executing the remaining lines of code. Instead of using the wait() function, you can use the Debris:AddItem() method to destroy the part after a certain delay. Here’s an updated version:

local PassId = 162973845
local ClickDetector = script.Parent.ClickDetector
local Glass = script.Parent.Glass
local CoverRemoved = script.Parent.Parent.CoverRemoved

ClickDetector.MouseClick:Connect(function(plr)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(plr.UserId, PassId) then
Glass.Anchored = false
Glass.Velocity = Vector3.new(0, 0, 50)
CoverRemoved.Value = true
– Destroy the part after 1 second
game:GetService(“Debris”):AddItem(script.Parent, 1)
end
end)