I’ve been trying to get the position of the player’s joystick on-screen. I’ve looked all over the forum with no luck, so I took a peak into the Core Gui and found it there.
The problem is, I’m not too sure how I would find out if they touched the joystick or not because of the value types.
Code:
local uis = game:GetService("UserInputService")
uis.TouchStarted:Connect(function(touch, gameProcessed)
if gameProcessed then return end
if not uis.TouchEnabled then return end
local touchGui = player.PlayerGui:FindFirstChild("TouchGui")
if not touchGui then return end
local tcf = touchGui:FindFirstChild("TouchControlFrame")
if not tcf then return end
local dynamicT = tcf:FindFirstChild("DynamicThumbstickFrame")
local size = dynamicT.Size
local inputPos = UDim2.fromScale(touch.Position.X, touch.Position.Y)
print(size, inputPos)
if (size - inputPos) < 50 then
print("hit joystick")
end
end)
Error: Attempt to compare UDim2 < number
(coming from line if (size - inputPos) < 50 then)
Nope. Says that" AbsoluteSize is not a valid member of UDim2". Tried comparing with Vector2 values after I found out it was a property of the Frame, with still no luck.
Here is the updated code:
local function checkTouch(touch:InputObject, gameProcessed:boolean)
if gameProcessed then return end
if not uis.TouchEnabled then return end
if touch.UserInputType ~= Enum.UserInputType.Touch then return end
local touchGui = player.PlayerGui:FindFirstChild("TouchGui")
if not touchGui then return end
local tcf = touchGui:FindFirstChild("TouchControlFrame")
if not tcf then return end
local dynamicT = tcf:FindFirstChild("DynamicThumbstickFrame")
if not dynamicT then return end
local size = dynamicT.Size
if dynamicT.AbsoluteSize - Vector2.new(touch.Position.X, touch.Position.Y) < Vector2.new(50, 50) then
print("hit joystick")
return false
else
return true
end
end
uis.InputBegan:Connect(function(input, processed)
if processed then return end
local valid
if uis.TouchEnabled and not uis.MouseEnabled then
if input.UserInputType == Enum.UserInputType.Touch then
valid = checkTouch(input, processed)
end
if valid then
processThrow()
end
else
processThrow()
end
end)
Update: I’ve solved the problem.
I checked the size of the UI within the player, stored it in a variable, and got the touch’s position as a Vector2 using uis.TouchTapInWorld. I then converted it to a UDim2, and compared each scale component with that of the variable. If they touched within that frame (e.g. they are using the joystick), it would not run the code that would’ve run if they didn’t touch it.