Players.player.PlayerGui.LocalScript:5: attempt to index nil with 'Destroy'

I need to make the VIP door open.

Roblox forum problem6

local player = game:GetService("Players").LocalPlayer
local market = game:GetService("MarketplaceService")

if market:UserOwnsGamePassAsync(player.UserId, 11100023) then
	game.Workspace:FindFirstChild("GamepassDoor"):Destroy()
else
	game.Workspace.GamepassDoor.Touched:Connect(function()
		market:PromptGamePassPurchase(player, 11100023)
	end)
end

Please help me!

game.Workspace:WaitForChild("GamepassDoor"):Destroy()

1 Like

This will make sure the item exists before deleting.

local Door = game:GetService("Workspace"):FindFirstChild("GamepassDoor")
if Door ~= nil then
Door:Destroy()
end
1 Like

This might be the result because you tried to destroy a door that you already destroyed beforehand. Have you tried making the script just make the door transparent and non-collidable?

> if market:UserOwnsGamePassAsync(player.UserId, 11100023) then
>   game.ReplicatedStorage.GamepassDoor:FireServer()

– Script

game.ReplicatedStorage.GamepassDoor.OnServerEvent:Connect(function()
game.Workspace:WaitForChild(“GamepassDoor”):Destroy()
end)