The error:
1 | 23 : 05 : 46.807 - Players.MinecraftButterfly 87. PlayerGui.StaffDoorScript: 23 : attempt to index nil with 'PlayerHasPass' |
The LocalScript inside StarterGui:
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | if game.MarketplaceService:PlayerOwnsAsset(player, 9304750 ) then |
3 | game.Workspace.Backdrop.Obby.VIP.CanCollide = false |
4 | end |
5 | 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:
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | if game:GetService( "MarketplaceService" ):UserOwnsGamePassAsync(player.UserId, 9304750 ) then |
3 | workspace.Backdrop.Obby.VIP.CanCollide = false |
4 | end |
5 | 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:
1 | repeat wait() until game:GetService( "Players" ).Character |
2 |
3 | if game:GetService( "MarketplaceService" ):UserOwnsGamePassAsync (game:GetService( "Players" ).LocalPlayer.UserId, 9304750 ) then |
4 | game.Workspace.Backdrop.Obby.VIP.CanCollide = false |
5 | end |