UserId is not a valid member of Model "[Player Username]"

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

When player buys the gamepass, they get the asset. But when they respawn, the asset stays in character.

  1. What is the issue?

When player respawns, an error occurs saying “UserId is not a valid member of Model “[Player Username]”” and the player doesn’t receive their asset.

I seriously don’t know why this is happening…

Here is the code:

wait(1)
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("RadioEvent")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local RadioSongGui = StarterGui.RadioSongGui
local Radio = RadioSongGui.Radio
local RadioBrick = workspace.Folder.RadioGamePassBrick
local GamepassID = 24358592

local function PromptPurchase(otherpart)
	local player = Players:GetPlayerFromCharacter(otherpart.Parent)
	MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end

local function GiveRadio(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local newRadio = Radio:Clone()
	newRadio.Parent = Character
	newRadio.CFrame = Character.Torso.CFrame * CFrame.Angles(0, math.pi, 0)
	local weld = Instance.new("Weld")
	weld.Part0 = newRadio
	weld.Part1 = Character.Torso
	weld.C0 = newRadio.CFrame:inverse()
	weld.C1 =  Character.Torso.CFrame:inverse()
	weld.Parent = newRadio
	
	Event:FireClient(Player)
end

local function OwnsGamepass(Player, Gamepass_ID)
	return MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepass_ID)
end

local function CheckIfOwnsGamepass(Player)
	print("TESTING")
	Player.CharacterAdded:Connect(function(character)
		print("CHARACTER TESTING PRINTED")
		if OwnsGamepass(character, GamepassID) then
			GiveRadio(character)
		end
	end)
end

local function GamepassPurchased(Player, PurchasedGamepassID, PurchasedValue)
	
	if PurchasedValue then
		
		if PurchasedGamepassID == GamepassID then
			
			GiveRadio(Player)
		end
	end
end

for _, player in Players:GetPlayers() do
	task.spawn(function()
		CheckIfOwnsGamepass(player)
	end)
end

Players.PlayerAdded:Connect(CheckIfOwnsGamepass)
RadioBrick.Touched:Connect(PromptPurchase)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(GamepassPurchased)
2 Likes

I already posted the solution to this problem here: Players.PlayerAdded doesn't fire for some reason - #3 by EntryRoot

2 Likes

oh my god i’m such an idiot. haha thanks!!

1 Like

UserId is a property of the client’s player object, not their character model.

2 Likes