I am making a click effect and to do this I need to find the location of the mouse on the screen. I intend for this effect to happen in the middle of the mouse.
This works fine when I click in the middle of screen as you can see from this image:
But when clicking at the top or bottom of my screen the mouse position seems to be vertically inaccurate as the position is either too high or low:
This is the script I am using to do this:
local userInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local playerGui = player:WaitForChild("PlayerGui")
local ScreenGui = playerGui:WaitForChild("ScreenGui")
local replicatedStorage = game:GetService("ReplicatedStorage")
local mouseParticleTemplate = replicatedStorage:WaitForChild("mouseParticle")
local tweenService = game:GetService("TweenService")
local goal = {}
goal.ImageTransparency = 1
local tweenInfo = TweenInfo.new(
0.1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false
)
local function onInputBegan(input, _gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouseParticle = mouseParticleTemplate:Clone()
mouseParticle.Parent = ScreenGui
mouseParticle.Position = UDim2.new(mouse.x/mouse.ViewSizeX,0,mouse.y/mouse.ViewSizeY,0)
mouseParticle.Visible = true
mouseParticle:TweenSize(UDim2.new(0.055, 0,0.101, 0),"Out", "Linear", 0.1)
local tween = tweenService:Create(mouseParticle, tweenInfo, goal)
tween:Play()
end
end
userInputService.InputBegan:Connect(onInputBegan)
Any thoughts on how I could get the mouse location more accurate?