[Still unsolved] Help with an If/Else not working as intended

  1. What do you want to achieve?
    Hello, I have made a door that I only want to open if a player buys the gamepass OR if they have “Access”, a BoolValue inside their player assigned by a different script.
    That script was tested and does work as intended.
    I have an If that check is a player has access or if they own the gamepass, and it prompts them to purchase it if they do not.

  2. What is the issue?
    The if statement seems to ignore the check and prompts them to buy the gamepass no matter what (goes directly to the else)

  3. What solutions have you tried so far?
    I tried re-writing it a few times, but I am new to scripting so I don’t even know what’s wrong.

local MS = game:GetService("MarketplaceService")
local gamepassid = [Redacted for my privacy]
local Door = script.Parent


Door.Touched:Connect(function (hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local user = plr.Name
		if game.Players[user].Access.Value == true or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == true then
	else
		MS:PromptGamePassPurchase(plr, gamepassid)
		end
		end
end)

local MS = game:GetService("MarketplaceService")
local gamepassid = [Redacted for my privacy]
local Door = script.Parent


Door.Touched:Connect(function (hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		if plr.Access.Value == true or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) then
		    --Script that opens the door
		else
		   MS:PromptGamePassPurchase(plr, gamepassid)
		end
	end
end)

Try this:

local MS = game:GetService("MarketplaceService")
local gamepassid = --your id
local Door = script.Parent

Door.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
        local user = plr.Name
        if game.Players[user].Access.Value == true or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == true then
            print(user .. " already owns gamepass")
            --open door code
        else
            MS:PromptGamePassPurchase(plr, gamepassid)
        end
    end
end)
local MS = game:GetService("MarketplaceService")
local gamepassid = id here
local Door = script.Parent

Door.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local user = plr.Name
		if game.Players[user].Access.Value == true or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == true then
			print(user.." already owns gamepass")
		else
			MS:PromptGamePassPurchase(plr, gamepassid)
		end
	end
end)
-- correction

@bloksskywalker, could you please test my code?

I still cannot figure out why but the door prompts the purchase even though I have access, and I have tested it with all the code here so far. I am starting to think maybe another script is causing this…

Ok, so you are saying they work but the door is not opening?

The door does open but the gamepass purchase gets prompted anyway, which is what I was trying to prevent

Ok then change this line to this:

elseif game.Players[user].Access.Value == false or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == false then
    MS:PromptGamePassPurchase(plr, gamepassid)

@bloksskywalker, please let me know if this works or not

It did not work. I even put a print between the prompt and the elseif to verify it was this script prompting the purchase and it did print so it was.

That’s weird, it should work. Did you misspell or forgot to add an end?

I don’t think so, but here is the whole script again and you can check if you want. Thanks for your help anyway.

local MS = game:GetService("MarketplaceService")
local gamepassid = [Redacted for privacy]
local Door = script.Parent

Door.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		local user = plr.Name
		if game.Players[user].Access.Value == true or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == true then
			print(user .. " already owns gamepass")
		elseif game.Players[user].Access.Value == false or MS:UserOwnsGamePassAsync(plr.UserId, gamepassid) == false then
			print("This script is causing the prompt")
			MS:PromptGamePassPurchase(plr, gamepassid)

		end
	end
end)

Sorry, just realized this but you forgot one more end for the elseif statement