Command: Return Mouse.Target issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make mobile support, and improve the remote function for better version. It has double tap, and click for devices and makes chat system message.
  2. What is the issue? Include screenshots / videos if possible!
    It didn’t returned the mouse.Target
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did looked everywhere, but I can’t find anything.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local gotMouse = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("GotMouse")
local mouse = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local LastTouch = tick()

gotMouse.OnClientInvoke = function()
 
 --[[
 the system message worked
 ]]
 
 local connection
 connection = UserInputService.InputBegan:Connect(function(input, processed)
  if processed then
   return
  end
  
  if input.KeyCode == Enum.UserInputType.MouseButton1 then
   connection:Disconnect()
   return mouse.Target
  elseif input.KeyCode == Enum.UserInputType.Touch then
   local timeSinceLastTouch = tick() - LastTouch
   if timeSinceLastTouch <= 0.25 then
    connection:Disconnect()
    return mouse.Target
   end
   LastTouch = tick() -- i forgot to add, so it doesn't mess it up.
  end
 end)
end)

Assistant doesn’t helped me well, because it can’t make connection looped. Also the server command run this if i say something, that needs a mouse target.

1 Like

Basically return mouse.target is making it return the object to the previous function, that is, it returns the result to this function:

so:

local gotMouse = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("GotMouse")
local mouse = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local LastTouch = tick()

gotMouse.OnClientInvoke = function()

 --[[
 the system message worked
 ]]

	local connection, Target
	connection = UserInputService.InputBegan:Connect(function(input, processed)
		if processed then	return	end
		if input.KeyCode == Enum.UserInputType.MouseButton1 then
			connection:Disconnect()
			Target = mouse.Target
		elseif input.KeyCode == Enum.UserInputType.Touch then
			local timeSinceLastTouch = tick() - LastTouch
			if timeSinceLastTouch <= 0.25 then
				connection:Disconnect()
				Target = mouse.Target
			end
		end
	end)
	
	while not Target do		task.wait()		end
	return Target
end
2 Likes

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