Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

Script doesnt know what player is so type this under function

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
0
I got this error: Workspace.Part.Script:7: attempt to index nil with 'UserId' Tyserkhan004V2 0 — 4y
0
i know, but you never told the script what is "player" you cant get UserId from nothing jerryisgod29 176 — 4y
Ad

Answer this question