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

Unable to cast value to Object?

Asked by
lytew 99
5 years ago

I created this script to make that roblox purchase screen appear for those who do not have a GamePass and DO NOT appear for those who have it. The problem is that this error is showing "Unable to cast value to Object, on line 21" and the screen sells does not appear.

01local Gamepass1 = workspace.LEVEL2_MAP.GamePasstouch
02 
03 
04local Id1 = 2544515
05 
06 
07local debounce = false
08Gamepass1.Touched:Connect(function(t)
09    if t.Parent:FindFirstChild('Humanoid') then
10    if debounce == false then
11        debounce = true
12    local haspass = false
13    local name = t.Parent.Name
14    local b = game.Players:FindFirstChild(name)
15        local success, message = pcall(function()
View all 31 lines...

1 answer

Log in to vote
1
Answered by
ImTrev 344 Moderation Voter
5 years ago
Edited 5 years ago
01local Gamepass1 = workspace.LEVEL2_MAP.GamePasstouch
02local Id1 = 2544515
03 
04local debounce = false
05Gamepass1.Touched:Connect(function(t)
06    if t.Parent:FindFirstChild('Humanoid') then
07        if not debounce then
08            debounce = true
09        local haspass = false
10        local name = t.Parent
11        local b = game.Players:GetPlayerFromCharacter(name)
12        local success, message = pcall(function()
13            haspass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(b, Id1)
14        end)
15        if not haspass then
View all 26 lines...

I found your error, when using "PromptGamePassPurchase", you have to pass the player as the first argument, not the UserId!

Ad

Answer this question