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

How do I fix this? -attempt to index nil with 'UserId'-

I am trying to get this script to prompt a purchase to the gamepass if they don't own it, but if they do then it puts the tools in the locations shown below. I keep getting this error though and I don't know what to do to fix this, any help?

local GamePassService = game:GetService("MarketplaceService")
local GamepassId = 0 -- 0 for purpose of asking

		script.Parent.Touched:Connect(function(hit)
			if GamePassService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
		
		game.ServerStorage.FlyingCarpet:Clone().Parent = player.Backpack
		game.ServerStorage.FlyingCarpet:Clone().Parent = player.StarterGear
	
	end	
end)


1 answer

Script doesnt know what player is so type this under function

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

2 comments

0

I got this error: Workspace.Part.Script:7: attempt to index nil with 'UserId'

0

i know, but you never told the script what is "player" you cant get UserId from nothing

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