When the players taps somewhere on the screen within the plot, the object goes there and if they want to confirm placement, they click on the green button “Place”
However when they click the Place button it looks like they also tap within the 3D workspace so the object goes there instead, wondering how to disable that?
connection2 = game:GetService("UserInputService").InputBegan:Connect(function(input,gp)
if gp then return end
-- computer building version here
-- mobile placement:
BuildingGui.Parent.Place.MouseButton1Click:Connect(function()
-- code irrelevant to the problem (to place the object)
end)
end)
It doesn’t work properly on mobile as on mobile, you need to tap, there is no hovering, here you need to kinda hold the button for the function to be ran and be recognised, plus it returns a table with no objects in it.
Is there no function to disable input or interaction within the 3D workspace directly when clicking on a UI?
You got my point wrong, you run game:GetService("StarterGui"):GetGuiObjectsAtPosition() WHEN the user clicks, on the position where he clicked (Screen Position)
Turn this on for a container frame (something that ideally encompasses the whole bottom toolbar, such as your scrollbars), it’ll sink input and won’t allow any interaction with the 3D world. More explanations available on the documentation page.
Just tried and no results from that. I even made a frame that covers the whole screen and made it Active and I couldn’t move my character but I could move the object still, could things be overriding because of my placement script?
I’m not exactly sure how you’re doing your placement because you’ve taken out that entire portion of code (either the code itself or a very, very detailed explanation of how you accomplish object placement would be appreciated), but that doesn’t sound right?
I just made a quick repro in Studio with an active frame covering the entire screen and a script that prints the local mouse’s target when MouseButton1 input is sent and it won’t interact with the 3D world. My case works but yours supposedly doesn’t. Either you need to check you properly set Active on these objects or you need to provide more detail.
The following script does not print when you click:
local UserInputService = game:GetService("UserInputService")
local LocalMouse = game:GetService("Players").LocalPlayer:GetMouse()
UserInputService.InputBegan:Connect(function (inputObject, gameProcessedEvent)
if gameProcessedEvent then return end
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
print("Clicked")
print(LocalMouse.Target)
end
end)
Gui consists of a single stretched frame across the viewport with Active on:
Okay, I see where the problem is, so I have two things:
-- Snap function basically makes object go to the mouses position
--and its the formula for snapping objects to the grid.
--But I am running a .RenderStepped event, thus when clicking UI it still clicks
--in the 3D world I am guessing
connection = game:GetService("RunService").RenderStepped:Connect(function()
if obj ~= "Path" then
Snap(clone,workspace.Plots[plotName].SizeBlock,4)
else
Snap(clone,workspace.Plots[plotName].SizeBlock,8)
end
mouse.Icon = "rbxassetid://6373607089"
end)
connection2 = game:GetService("UserInputService").InputBegan:Connect(function(input,gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and not touching then
-- code to place object
end
end)
So we need to switch the RenderStepped event to be a InputBegan event I believe?
Edit: Tested it, works with InputBegan but I’d always like the objects position to be updated, how will I do that?
It would probably be wiser at this point to separate the ways you code movement and placement between computer devices and mobile then so you can avoid this issue. Most building games, even off platform, control very differently on mobile than they do on computer devices in light of things like this.
For a computer device, it will have no problem using a mouse in order to determine the grid in which an object should be placed on. You can also just click and interact with the object or place it down. For mobile, the typical workflow is that the object’s movement is only changed when holding down on the screen and then there are on-screen buttons to place, cancel and whatever other actions you need.
Consider using TouchMoved to determine when the user moves their finger on the screen and then ViewportPointToRay to convert the 2D positions of their touch to a 3D position - this will help you find the grid that you need to snap to. From there, it should interfere minimally with your placement Guis. You might need to accommodate for this in your RunService connection* so that the object doesn’t snap to your finger’s location.
* I recommend using Heartbeat over RenderStepped. RenderStepped is something you should typically use scarcely, like for camera and character transparency updates.
I always put a transparent button, that is not assigned to anything, behind my gui, so if the gui is clicked, it thinks im clicking on the invisible button