Is there a way to add on-screen effects using Player:GetMouse()?

Using the mouse object, you can see the X and Y coordinates of the pointer: all you’d have to do is place a GUI a little bit higher when clicked.

2 Likes

Local script.
Get player.
Get mouse
Make a Tool.Activated connection
Clone or Instance.new a GUI
Get mouse pos
Position = UDim2.new(0, pos.X, 0, pos.Y-36)

if you need a code example lemme know

As for @BitLang you don’t have to place the gui higher, you can either use the offset on the Y that i showed or on the screen gui settings Enable IgnoreGuiInset and then change the position of UI to UDim2.new(0, pos.X, 0, pos.Y)

Btw pos is mousePos

2 Likes

“you don’t have to place the gui higher, you can either use the offset on the Y that i showed”
What do you think I meant by “place it higher”?

1 Like

Yes. Could you show me a code example?

1 Like

BTW, a better way to do this is not by getting player:GetMouse(), but instead the first argument in tool.Equipped. For example:

tool.Equipped:Connect(function(mouse)
    -- code here
end)

Anyway, just use tool.Activated. When it’s activated, set a TextLabel’s Visible property to true, and make its Position property to UDim2.new(0, mouse.X, 0, mouse.Y)

Then use task.wait(1) and replace 1 with how many seconds to wait. Then, set TextLabel’s Visible property back to false.

Alternatively, if you wanna make a little animation, you could set the Position property to UDim2.new(0, (mouse.X), 0, (mouse.Y - 20)).
EDIT: I just realized you only need to subtract 20 px from the Y. I just fixed it.
Then, use TextLabel:TweenPosition(UDim2.new(0, mouse.X, 0, mouse.Y))

That will essentially spawn the text 20 pixels below where it moves to. Then it moves with an animation that takes 1 second. You can adjust the 20 if it’s too short of an animation.

Hope this helps, as I’ve never done this myself before.

2 Likes

Code example (untested written on mobile so might have typos)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent

tool.Activated:Connect(function()
    local ui = myUi:Clone()
    ui.Parent = player.PlayerGui
    ui.TextLabel.Position = UDim2.new(0, mouse.X, 0, mouse.Y - 36)
end)
3 Likes

Absolutely! I’ve already made something that replaces the cursor with a 3D animated hand here. There are tons of notes included to show you what’s going on with the mouse and the Gui at any given time.

It’s pretty easy to make any Gui object follow the mouse’s position and do stuff with it whenever you click, drag, or do whatever with the mouse.

1 Like
local plr = -- path to player
local mouse = -- path to mouse (I AM TOO LAZY TO WRITE)
local tool = -- path to tool
local urui = -- path to ui

tool.Activated:Connect(function()
local clone = urui:Clone()
clone.Parent = plr.PlayerGui
local ui = clone. -- path to ur frame/textlabel/whatever ui element
ui.Position = Udim2.new(0,mouse.X,0,mouse.Y)
end)
1 Like

This is the same script I have except yours doesn’t account for gui inset

1 Like

I didnt saw ur script. Sorry lol.

2 Likes

@AustnBlox have you found a solution. If so don’t forget to mark it

2 Likes

Full script:

local tool = nil -- replace nil with the path of your tool!
local label = nil -- replace nil with the path to your TextLabel

tool.Equipped:Connect(function(mouse)
    tool.Activated:Connect(function()
        label.Visible = true
        label.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
        task.wait(1)
        label.Visible = false
    end)
end)

OR, if you want tweening:

local tool = nil -- replace nil with the path of your tool!
local label = nil -- replace nil with the path to your TextLabel

tool.Equipped:Connect(function(mouse)
    tool.Activated:Connect(function()
        label.Visible = true
        label.Position = UDim2.new(0, mouse.X, 0, mouse.Y - 20)
        -- if you want the label to go up instead of down, change the "- 20" to "+ 20".
        
        label:TweenPosition(UDim2.new(0, (mouse.X), 0, (mouse.Y - 20)))
        task.wait(1)
        label.Visible = false
    end)
end)

Boom! There you go. LMK if you have any questions!

1 Like

This doesn’t make it visible or disappear after, however.

Yeah, with a loop and player:GetMouse. But with a tool, tool.Equipped’s argument.

It doesn’t have to, that was just a code example, I was not breaking TOS by giving a full script/system I know @AustnBlox knows how to code good so he can handle that.

It’s better & more efficient.

Ok?

There’s different ways to get 3d spaces translated to a 2d space.
Look at these functions

(for ray casting)
https://developer.roblox.com/en-us/api-reference/function/Camera/ScreenPointToRay
https://developer.roblox.com/en-us/api-reference/function/Camera/ViewportPointToRay

(for position)
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint

(for mouse, mouse location on 2d screen, not 3d)
https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetMouseLocation

GetMouseLocation goes with ScreenPointToRay or ViewportPointToRay to translate its 2d space to 3d space. And because it’s ray casting, this allows you to get more info than Mouse.Target such as Normal, Material, Mouse position on part and have better part filtering. Sure you could also just use Mouse.Hit to get the 3d CFrame but as mentioned by Roblox, it was superseded by GetMouseLocation.

A list of things returned by ray casts for ScreenPointToRay or ViewportPointToRay:
https://developer.roblox.com/en-us/api-reference/datatype/RaycastResult

1 Like

Golly jee, all of that isn’t needed.

Actually it is needed. GetMouse() has been superseded and is less feature rich than the newer options.

It still gets the job done… you literally just read that from their docs page hahahah