When I click on the touch screen the place of purchase does not seem

How to fix it

it has to be this

Script:

-- Core UI localscript

local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools

local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport


game.ReplicatedStorage.SendEquipped.OnClientEvent:Connect(function(equipped)
	equippedItem.Value = equipped
	if equippedItem.Value ~= "" then
		local fakecam = Instance.new("Camera")
		fakecam.Parent = equippedItemViewport
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
		handle.Parent = equippedItemViewport
		equippedItemViewport.CurrentCamera = fakecam
		fakecam.CFrame = handle.CameraCFrame.Value
	end
end)

shopButton.MouseButton1Click:Connect(function()
	mainFrame.Visible = not mainFrame.Visible
end)

local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25

local item1 = itemFrame:WaitForChild("Item1")

local box
local numRows = 1

for i = 1,numberOfItems,1 do
	
	if i == 1 then
		box = item1
	else
		
		box = item1:Clone()
		box.Name = "Item"..i
		box.Parent = itemFrame
		
		
		if (i-1) / (4*numRows) == 1 then
			-- New row
			numRows = numRows + 1
			box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(numRows - 1))
		else
			-- Add to x only
			box.Position = itemFrame["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
		end
		
	end
	
	
	box.MouseButton1Click:Connect(function()
		for _, v in pairs(itemViewport:GetChildren()) do
			if not v:IsA("Frame") then
				v:Destroy()
			end
		end
		
		local itemViewportCam = Instance.new("Camera")
		itemViewportCam.Parent = itemViewport
		
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
		handle.Parent = itemViewport
		
		itemViewport.CurrentCamera = itemViewportCam
		itemViewportCam.CFrame = handle.CameraCFrame.Value
		
		local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])
		
		if equippedItem.Value == availableTools[i][1] then
			infoFrame.Cash.Text = "Owned"
			infoFrame.BuyButton.Text = "Unequip"
		elseif owned == true then
			infoFrame.Cash.Text = "Owned"
			infoFrame.BuyButton.Text = "Equip"
		else
			infoFrame.BuyButton.Text = "Buy"
			infoFrame.Cash.Text = "$"..availableTools[i][2]
		end
		
		infoFrame.ItemName.Text = availableTools[i][1]
		selectedItem.Value = availableTools[i][1]
		
		for _, v in pairs(itemFrame:GetChildren()) do
			if v:IsA("ImageButton") then
				v.BorderSizePixel = 0
			end
		end
		
		itemFrame["Item"..i].BorderSizePixel = 2
		
	end)
	
	local fakeCam = Instance.new("Camera")
	fakeCam.Parent = box.VPF
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
	handle.Parent = box.VPF
	box.VPF.CurrentCamera = fakeCam
	fakeCam.CFrame = handle.CameraCFrame.Value
	itemFrame["Item"..1].ItemName.Text = availableTools[i][1]
	
end


buyButton.MouseButton1Click:Connect(function()
	local result = game.ReplicatedStorage.PurchaseItem:InvokeServer(selectedItem.Value)
	if result == true then
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Bought!"
		wait(0.5)
		buyButton.Text = "Equip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "NotEnoughBucks" then
		buyButton.BackgroundColor3 = Color3.fromRGB(204,31,31)
		buyButton.Text = "Not enough bucks!"
		wait(0.5)
		buyButton.Text = "Buy"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Equipped" then
		equippedItem.Value = selectedItem.Value
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Equipped!"
		wait(0.5)
		buyButton.Text = "Unequip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Unequipped"  then
		equippedItem.Value = ""
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Unequipped"
		wait(0.5)
		buyButton.Text = "Equip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	end
end)


if equippedItem.Value ~= "" then
	local fakecam = Instance.new("Camera")
	fakecam.Parent = equippedItemViewport
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
	handle.Parent = equippedItemViewport
	equippedItemViewport.CurrentCamera = fakecam
	fakecam.CFrame = handle.CameraCFrame.Value
end

equippedItem:GetPropertyChangedSignal("Value"):Connect(function()
	if equippedItem.Value ~= "" then
		
		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
		
		local fakecam = Instance.new("Camera")
		fakecam.Parent = equippedItemViewport
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
		handle.Parent = equippedItemViewport
		equippedItemViewport.CurrentCamera = fakecam
		fakecam.CFrame = handle.CameraCFrame.Value
	else
		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
	end
end)
1 Like

It looks like your using MouseButton1Clicked however as you are trying this on a Mobile device, you may be better off using ContextActionService or .Activated instead depending on your needs.

https://devforum.roblox.com/t/register-click-on-mobile-and-mousebutto/503857/5

im trying to do it, but it’s not happening, can you help? maybe I’m doing it wrong, can you add contextactionservice if you can you add?

1 Like

first try debugging it to see if it even fires so add a print(“abababa”) after the mousebutton1click event

when playing on the computer, the print text appears, but the print text does not appear on the mobile, this is where the script is located

box.InputBegan:Connect(function(input, gameProcessedEvent)
		if input.UserInputType == Enum.UserInputType.MouseButton1 or 
			(input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent) then
			print("Working")
			
			for _, v in pairs(itemViewport:GetChildren()) do
				if not v:IsA("Frame") then
					v:Destroy()
				end
			end

			local itemViewportCam = Instance.new("Camera")
			itemViewportCam.Parent = itemViewport

			local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
			handle.Parent = itemViewport

			itemViewport.CurrentCamera = itemViewportCam
			itemViewportCam.CFrame = handle.CameraCFrame.Value

			local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])

			if equippedItem.Value == availableTools[i][1] then
				infoFrame.Cash.Text = "Owned"
				infoFrame.BuyButton.Text = "Unequip"
			elseif owned == true then
				infoFrame.Cash.Text = "Owned"
				infoFrame.BuyButton.Text = "Equip"
			else
				infoFrame.BuyButton.Text = "Buy"
				infoFrame.Cash.Text = "$"..availableTools[i][2]
			end

			infoFrame.ItemName.Text = availableTools[i][1]
			selectedItem.Value = availableTools[i][1]

			for _, v in pairs(itemFrame:GetChildren()) do
				if v:IsA("ImageButton") then
					v.BorderSizePixel = 0
				end
			end

			itemFrame["Item"..i].BorderSizePixel = 2
		end
	end)

Why did you change it to inputtype mousebutton1? Reverse it to mousebutton1down instead and then debug it. Its not going to work with userinputtype.mousebutton1, that only detects when an actual mouse clicks but mousebutton1down on a gui object just detects when it has been clicked by anything either by a finger controller mouse whatever it is whenever its pressed down it fires. So reverse the script back and do it with box.MouseButton1Down:Connect(function() and debug see what happens

1 Like

Thank you it worked!
random:asdsadsadasdasdsaddas

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.