Building UI: Object moves when player clicks on ui

Hi! So ive been working on a building ui but the problem is if the player is on mobile when they click on ui like rotating or placing the model moves to the object. Is there any simple way to fix this?

Here is my code for mobile

									UIS.TouchTapInWorld:Connect(function()
											mouse.TargetFilter = previewobject
											if previewobject:FindFirstChild("MainPart") then
												local objectcframe = CFrame.new(math.round(mouse.Hit.Position.X/grid)*grid,math.round(mouse.Hit.Position.Y+previewobject.PrimaryPart.Size.Y/2), math.round(mouse.Hit.Position.Z/grid)*grid)
												local objectangles = CFrame.Angles(0, math.rad(rotationamount), 0)
												previewobject:SetPrimaryPartCFrame(objectcframe*objectangles)
											end
									end)
2 Likes

userinputservice.TouchTapInWorld has two parameters: position and processedByUI

so you can just do:

game.UserInputService.TouchTapInWorld:Connect(function(position, processedByUI)
	if not processedByUI then
           -- code
    end
end)
1 Like

I tried your solution for some reason it still isnt working:

								UIS.TouchTapInWorld:Connect(function(pos, proccesed)
									if not proccesed then
										mouse.TargetFilter = previewobject
										if previewobject:FindFirstChild("MainPart") then
											local objectcframe = CFrame.new(math.round(mouse.Hit.Position.X/grid)*grid,math.round(mouse.Hit.Position.Y+previewobject.PrimaryPart.Size.Y/2), math.round(mouse.Hit.Position.Z/grid)*grid)
											local objectangles = CFrame.Angles(0, math.rad(rotationamount), 0)
											previewobject:SetPrimaryPartCFrame(objectcframe*objectangles)
										end
									end

								end)

I don’t know, I don’t use this often. Try reading this article for help.

1 Like

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