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

how do i make a premium only door that prompts premium if you dont have it?

Asked by 4 years ago

i tried this and everything seems ok but nothing works?

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
        if player.MembershipType == Enum.MembershipType.Premium then

            script.Parent.CanCollide = false
            wait(0.1)
            script.Parent.CanCollide = true

        else
            -- prompt premium purchase
            MarketplaceService:PromptPremiumPurchase(player)
            h.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent["TeleportPart"].Position)

        end
    end
end)

1 answer

Log in to vote
1
Answered by
P100D 590 Moderation Voter
4 years ago
Edited 4 years ago

Since this isn't a LocalScript, Players.LocalPlayer won't work, as this method only works in a LocalScript. (If this is a LocalScript, the script won't run at all if it's in Workspace)

To find the player, you can use Players:GetPlayerFromCharacter()

Example:

script.Parent.Touched:Connect(function(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if (humanoid ~= nil) then
        player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
    end
end)
Ad

Answer this question