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.
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)
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)
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
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…
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)