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

How do I make my proximity prompt compatible with mobile?

local PlayerManager = require(script.Parent.Parent.PlayerManager)

local Button = {}
Button.__index = Button

function Button.new(tycoon, part)
	local self = setmetatable({}, Button)
	self.Tycoon = tycoon
	self.Instance = part
	
	return self
end

function Button:Init()
	self.Prompt = self:CreatePrompt()
	self.Prompt.Triggered:Connect(function(...)
		self:Press(...)
	end)
end

function Button:CreatePrompt()
	local prompt = Instance.new("ProximityPrompt")
	prompt.HoldDuration = 0.5
	prompt.ActionText = self.Instance:GetAttribute("Display")
	prompt.ObjectText = "$" .. self.Instance:GetAttribute("Cost")
	prompt.Parent = self.Instance
	return prompt
end

function Button:Press(player)
	local id = self.Instance:GetAttribute("Id")
	local cost = self.Instance:GetAttribute("Cost")
	local money = PlayerManager.GetMoney(player)
	
	if player == self.Tycoon.Owner and money >= cost then
		PlayerManager.SetMoney(player, money - cost)
		self.Tycoon:PublishTopic("Button", id)
		self.Instance:Destroy()
	end
end

return Button


1 answer

Proximity prompt is automatically compatible for mobile players and desktop users. for Mobile players they have to click the proximity prompt as for desktop users they can click a letter on keyboard or click it with their mouse.

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