Hi. So recently, I had a UserInputService script that didn’t work, and another scripter helped me fix it. However, now I am noticing a few bugs.
-
What do you want to achieve? I want to make the MouseButton1Down work exactly like the UserInputService.TouchTapInWorld function.
-
What is the issue? The MouseButton1Down function works, but it isn’t registering that the edges of the clicked parts exist.
-
What solutions have you tried so far? I’ve tried using a GuiInset, which actually made an offset, so that didn’t work.
Alright so, if you can help me make my MouseButton1Down function work exactly like the UserInputService.TouchTapInWorld function, that will help a lot, because on mobile, it registers that the edges of parts exist. Whereas on a PC with a mouse, it doesn’t register the edges of parts. Instead, you have to click directly in the middle completely avoiding edges. (If this is just a hit box issue that ROBLOX has, please let me know so you don’t have to waste your time.)
Here’s the code:
(THIS CODE IS IN A LOCALSCRIPT)
local Tool = script.Parent
local Client = game.Players.LocalPlayer
local TransferEvent = Tool:WaitForChild("Transfering")
local UserInputService = game:GetService("UserInputService")
local Camera = game.Workspace:WaitForChild("Camera")
local COOLDOWN = 2.3
local Cooling = false
local GuiService = game:GetService("GuiService")
local Inset = GuiService:GetGuiInset()
Activated = false
Tool.Equipped:Connect(function()
Activated = true
end)
if UserInputService.MouseEnabled == true then
UserInputService.InputBegan:Connect(function(iObject, Processed)
if iObject.UserInputType == Enum.UserInputType.MouseButton1 then
local Length = 5000
local unitRay = Camera:ViewportPointToRay(iObject.Position.X - Inset.X, iObject.Position.Y - Inset.Y)
local RayBeam = Ray.new(unitRay.Origin, unitRay.Direction * Length)
local hitPart, HitPos = workspace:FindPartOnRay(RayBeam)
if Activated == true and Cooling == false and TransferEvent ~= nil and hitPart then
print(hitPart.Name)
Cooling = true
TransferEvent:FireServer(HitPos)
task.wait(COOLDOWN)
Cooling = false
end
end
end)
elseif UserInputService.TouchEnabled == true then
UserInputService.TouchTapInWorld:Connect(function(Position, processedByUI)
local Length = 5000
if processedByUI then
return
end
local unitRay = Camera:ViewportPointToRay(Position.X, Position.Y)
local RayBeam = Ray.new(unitRay.Origin, unitRay.Direction * Length)
local hitPart, HitPos = workspace:FindPartOnRay(RayBeam)
if Activated == true and Cooling == false and TransferEvent ~= nil and hitPart then
Cooling = true
TransferEvent:FireServer(HitPos)
task.wait(COOLDOWN)
Cooling = false
end
end)
end
Tool.Unequipped:Connect(function()
Activated = false
end)