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

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

Asked by
Azuc 112
5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
Ad

Answer this question