Help! How do I make this script into a purchable product?

So I have a islands in my game that you access through teleporters on the main island. I wanted to know if there is a way I could make it so the only way a player could access the island is if the player buys the island with currency they earned in game. Here is the teleporting script

script.Parent.Touched:Connect(function(h)
	local hum = h.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		h.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace["tele1"].Position)
		script.Parent.Parent.tele1.Script.Disabled = true
		wait(5)
		script.Parent.Parent.tele1.Script.Disabled = false
	end
end)

All you really need to do is to check if the Player has bought it.
You could use Module Scripts for that!

script.Parent.Touched:Connect(function(h)
	local hum = h.Parent:FindFirstChild("Humanoid")
	if hum ~= nil and ModuleScript:UserOwnsIsland(Player) then
		h.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace["tele1"].Position)
		script.Parent.Parent.tele1.Script.Disabled = true
		wait(5)
		script.Parent.Parent.tele1.Script.Disabled = false
	end
end)
--This would be the Module Script
local module = {}
function module:UserOwnsIsland(Player)
   return --your logic here
end
return module

You will need to write the return statement in your module yourself; I don’t know how you handle Islands. :wink:

1 Like