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

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

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

✓ Accepted answer

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)

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