The error:
23:05:46.807 - Players.MinecraftButterfly87.PlayerGui.StaffDoorScript:23: attempt to index nil with 'PlayerHasPass'
The LocalScript inside StarterGui:
game.Players.PlayerAdded:Connect(function(player) if game.MarketplaceService:PlayerOwnsAsset(player,9304750) then game.Workspace.Backdrop.Obby.VIP.CanCollide = false end end)
What should I do to fix this error and make the door's CanCollide property be false for players who own the VIP gamepass?
You should be using UserOwnsGamePassAsync()
when using game passes. Here try this:
game.Players.PlayerAdded:Connect(function(player) if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9304750) then workspace.Backdrop.Obby.VIP.CanCollide = false end end)
Read about UserOwnsGamePassAsync()
here. If this helped, be sure to accept this answer!
You're supposed to use :UserOwnsGamePassAsync
. Also, don't use the PlayerAdded
event since LocalScripts
are automatically parented to every player when they are added. Try this:
repeat wait() until game:GetService("Players").Character if game:GetService("MarketplaceService"):UserOwnsGamePassAsync (game:GetService("Players").LocalPlayer.UserId, 9304750) then game.Workspace.Backdrop.Obby.VIP.CanCollide = false end