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

hi i need help idk what is wrong with this script? it saysGamepassId is not a valid member

whats wrong with this script

local debounce = false 

script.Parent.Touched:connect(function(hit)
  	if debounce == false then 
		wait()
		debounce = true 
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local GamePassId = script.Parent.GamepassId
		local marketplaceservice = game:GetService("MarketplaceService")
		if player and marketplaceservice:PlayerOwnsAsset(player, gamepassId.Value) then
			script.Parent.CanCollide = false
			wait(.5) 
			script.Parent.CanCollide = true
		end
	end
	wait(2)
	debounce = false 
end)

it says GamepassId is not a valid member of Part

1 comment

0

I'm going to assume that this is a Script, and according to my testing, it will error if you capitalize wrong (game.Workspace.name will error, game.Workspace.Name will not). My suggestion is for you to make sure that all references of GamepassId in your code is typed exactly the same, as I think it's case sensitive.

2 answers

✓ Accepted answer

Gamepasses are no longer assets they are their own class. You should not use PlayerOwnsAsset() and switch it out with UserOwnsGamePassAsync().

How you would use it in your script:

local debounce = false 

script.Parent.Touched:connect(function(hit)
    if debounce == false then 

        wait()

        debounce = true 

        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local GamePassId = script.Parent.GamepassId
        local marketplaceservice = game:GetService("MarketplaceService")

        if player and marketplaceservice:UserOwnsGamePassAsync(player, gamepassId.Value) then
            script.Parent.CanCollide = false

            wait(.5) 

            script.Parent.CanCollide = true
        end
    end

    wait(2)

    debounce = false 
end)

The script is untested but should work. Hope this helps!

1 comment

0

didnt work...

Case sensitivity is really important in lua, so if you accidentally use Part:DEstroy() instead of Part:Destroy(), it matters by a lot. Since :DEstroy doesn't exist, it will error something like, "DEstroy" is not a valid member of Part. I'll fix some errors you did on your script.

Line 10

if player and marketplaceservice:PlayerOwnsAsset(player, gamepassId.Value) then

should be

if player and marketplaceservice:PlayerOwnsAsset(player, GamePassId.Value) then

just like in Line 8 where it said:

local GamePassId = script.Parent.GamepassId

I hope this helps you.

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