Effect on cursor when screen is clicked

Im currently working on a simulator game. And I want to make it so when a player clicks the screen to get points, an UI kind of thing pops up where to cursor is, example below

This is the code I use to give someone points when they click

local player = game.Players.LocalPlayer
local Speed = player:WaitForChild("leaderstats"):WaitForChild("Speed")
local sound = script["Pop Sound!"]
local popup = game.Players.LocalPlayer.PlayerGui:WaitForChild("StarterScreen"):WaitForChild("Frame")


debounce = true


game:GetService("UserInputService").InputBegan:Connect(function(input, engine_processed)
if engine_processed then
		return
	end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if debounce == true then
			debounce = false
			Speed.Value = Speed.Value +1
			local Char = player.Character or player.CharacterAdded:Wait()
			local Hum = Char.Humanoid
			Hum.WalkSpeed = Speed.Value / 12
			sound:Play()
			wait(0.15)
			debounce = true
		end
	end
end)



1 Like

You could use a Tween to change the size of the frame and its position to accomodate if necessary. (if it’s exactly like the example, then you probably wouldn’t have to change the position because of how roblox ui is laid out, but if you’re doing it differently, you might have to)

Do you recon that you can explain that further?
Im quite new to this :slight_smile:

Sure.

Basically, a tween is like an animation.

An animation works by smoothing the transition of an object when it moves to point A to point B. A Tween does the same, but it allows you to do it with the properties of objects, like their size.

In the example, they do that by using a Tween to make the gui larger and reversing it back to its normal size.

1 Like

Thank you!,
How can I make the UI popup Occur where the cursor is when screen is clicked?

By “where the cursor is”, are you referring to where the mouse is on the screen?

I think that’s what you’re saying, just making sure so I don’t misunderstand.

Yes, as you can see in the example i posted, when i click it comes up with an UI that goes “1” that UI pops up where the screen was clicked

Ahh, alright, I see what you mean now.

This whole time, I thought you were talking about the gui on the left that grows for a moment, whoops, lol.

To me, it looks like that works by doing the following:

  1. Get the mouse’s position
  2. Pick a random spot within a radius around it
  3. Clone the number and use a Tween to move it to the selected location
  4. Use another Tween to enlarge and shrink it
  5. Destroy the number after it reaches its destination
1 Like

Haha, glad you understand now :slight_smile:

How would that look in a script?

Sorry for all the questions…

-- Step 1
local Mouse = game.Players.LocalPlayer:GetMouse()
local MousePosX = Mouse.X
local MousePosY = Mouse.Y

-- Step 2
local ToPosX = MousePosX + math.random(-50, 50)
local ToPosY = MousePosY = math.random(-50, 50)

-- Step 3
local GuiClone = Gui:Clone()
local MoveToTween = TweenService:Create(blah blah blah)
MoveToTween:Play()

-- Step 4
local SizeTween = TweenService:Create(more blah blah blah) -- but this one should only be half the duration of MoveToTween and shouls reverse once complete

-- Step 5
wait(duration of MoveToTween)
GuiClone:Destroy()
1 Like

What do I put in “Blah Blah Blath”?

That’s for the constructor arguments, which is a whole gaggle of fun you get to read up on in the TweenService Documentation.

The code samples should do a good job of guiding you along, so I think you’ll get it from there.

Alrighty, I will get reading then :slight_smile:

Lemme know if you need help with it, I should (usually) respond within a day.

1 Like

Will do mate, also thank you so much!

Im looking at the “Tween Creation” code sample, and I see the “Goal” thing in the script, is that something that I would need?

You don’t need to store it in a variable, but yeah, you need that. That tells the tween where the stopping point is.

Okay I see, how do I tell the script where the screen was clicked tough, the position varies so I can’t just put one position?

When whatever function you’re using runs, you can get the X and Y properties of the mouse to find it’s coordinates on-screen. Basically, something like this:

function GetMousePos()
  local Mouse = game.Players.LocalPlayer:GetMouse()
  local MouseX = Mouse.X
  local MouseY = Mouse.Y
  return MouseX, MouseY
end

Alrighty, So I have made this script where it detects when the player clicks the screen, how could I input what you said into it?

local gui = script.Parent



game:GetService("UserInputService").InputBegan:Connect(function(input, engine_processed)
	if engine_processed then
		return
	end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		
	end
end)