Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get this gamepass only door to work properly and not error out?

Keeps throwing this:

21:20:26.278 - userId is not a valid member of Part 21:20:26.278 - Stack Begin 21:20:26.278 - Script 'Workspace.Door.DONT DELETE IT', Line 6 21:20:26.279 - Stack End

or this:

21:20:25.397 - Argument 1 missing or nil 21:20:25.397 - Stack Begin 21:20:25.397 - Script 'Workspace.Door.DONT DELETE IT', Line 6 21:20:25.397 - Stack End

local debounce = true

script.Parent.Touched:connect(function(hit) 
    if hit.Parent:FindFirstChild("Humanoid") then
		local player = hit.Parent.Name
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId,3744704) then
            if debounce then
                debounce = false
                script.Parent.CanCollide = false
                wait(2)
                script.Parent.CanCollide = true
                debounce = true
            end
        end
    end
end)

1 answer

✓ Accepted answer

You are getting the player's name (a string value) that does not include UserId in it's properties. Instead, use FindFirstChild.

script.Parent.Touched:connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then 
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 3744704) then
			--code
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.