Hello, today I’m trying to change up my previous script a bit. Previously it took the mouse object and got the part it was pointing towards.
With me now trying to make my game more mobile friendly, I’m trying to fix a few bugs I found while emulating a mobile device. One bug involved this, and now I’m trying to get where a GUI frame object if pointed to, not the mouse.
If you don’t understand, I have set up a gui frame object that acts as the cursor, like shown below, and since mobile touches are different from a player’s mouse, I’m completely switching over to the frame object.
(the tiny dot in the center of the sceen)
This code gets the player’s mouse, not the frame object.
local function getMouseAndTargetLocation(cursorPosition)
local ray = workSpace.CurrentCamera:ScreenPointToRay(cursorPosition.x, cursorPosition.y, 1)
ray = Ray.new(ray.Origin, ray.Direction * 999)
return workSpace:FindPartOnRay(ray)
end
local function updateTooltip()
local text = ""
local target = getMouseAndTargetLocation(uiService:GetMouseLocation())
if target then
if target.Parent:FindFirstChild("Settings") then
if target.Parent.Settings:FindFirstChild("interact") then
if player:DistanceFromCharacter(target.Position) <= target.Parent.Settings.interact.distance.Value then
text = target.Parent.Settings.interact.tooltip.Value
end
end
end
end
cursor.Text = text
end
(this runs every Humanoid.Running, and so far it’s working pretty well.)