Effect on cursor when screen is clicked

Under the input check, you can write this:

local Mouse = game.Players.LocalPlayer:GetMouse()
local MouseX = Mouse.X
local MouseY = Mouse.Y
print(MouseX, MouseY)

Try that as a test run first.

It works!
it prints the postion of the mouse click

I also just got the random postion around cursor working by doing this

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
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local MouseX = Mouse.X
		local MouseY = Mouse.Y
		local ToPosX = MouseX + math.random(-50, 50)
		local ToPosY = MouseY + math.random(-50, 50)
		print(ToPosX,ToPosY)
		
	end
end) 

Sweet! Now you have to clone the gui and create the tween that’ll transition it to the random coordinates you got. I can’t look at the documentation to follow along with you until I can get on PC, so until I can, I want you to read the docs and try to figure it out on your own. If you have problems, lemme know and I’ll help you the best I can.

1 Like

Sounds good, so ive created this, and it does not seem to work, do you know why?

local gui = script.Parent
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(5)


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

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local MouseX = Mouse.X
		local MouseY = Mouse.Y
		local ToPosX = MouseX + math.random(-50, 50)
		local ToPosY = MouseY + math.random(-50, 50)
		local GuiClone = gui:Clone()
		local tween = TweenService:Create(GuiClone, tweenInfo)
		tween:Play()
	end
end) 

For TweenInfo, all of the properties must be defined if I’m not mistaken, and the goal must be defined after TweenInfo in the constructor as well.

I think I defined the goal here, but it still does not work?

local gui = script.Parent
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(5)


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

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local MouseX = Mouse.X
		local MouseY = Mouse.Y
		local ToPosX = MouseX + math.random(-50, 50)
		local ToPosY = MouseY + math.random(-50, 50)
		local GuiClone = gui:Clone()
		
		local goal = {}
		goal.Position = UDim2.new(ToPosX, ToPosY)
		
		local tween = TweenService:Create(GuiClone, tweenInfo, goal)
		
		tween:Play()
	end
end) 

A UDim2 is composed of two UDims, one for each axis, so constructing that would look like this:

local goal = {Position = UDim2.new(UDim.new(0, ToPosX), UDim.new(0, ToPosY))}

Also, you should go through the TweenInfo properties and define all of them. I don’t remember what order they’re in, but here are some settings you can use to at least move to the testing phase:

Enum.EasingStyle.Linear,
Enum.EasingDirection.Out

There should be one for the repeat count, make it 0.
There should also be a bool for if it reverses, make it false.
Other than the duration, that should be it, but lmk if there’s one I forgot.

Thank you!

I’ve come up with this now, but when I click nothing happens, I don’t even get any output errors

local gui = script.Parent
local TweenService = game:GetService("TweenService")



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

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local MouseX = Mouse.X
		local MouseY = Mouse.Y
		local ToPosX = MouseX + math.random(-50, 50)
		local ToPosY = MouseY + math.random(-50, 50)
		local GuiClone = gui:Clone()
		
		local goal = {Position = UDim2.new(UDim.new(0, ToPosX), UDim.new(0, ToPosY))}
		
		local tweenInfo = TweenInfo.new(
			2,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
			)
		
		local tween = TweenService:Create(GuiClone, tweenInfo, goal)
		
		tween:Play()
	end
end) 

Is the Gui visible and parented to PlayerGui?

Also, you probably shouldn’t parent the script to the gui since it would be duplicated too when you clone it.

I’ve checked and fixed all that now, but still no luck :frowning_face:

Might be because it’s trying to change the position of a screengui instead of a frame. Add a frame to the gui and make it the target of the tween instead.

The popup GUI is already on a frame

Alright, then set the target of the tween to GuiClone.Frame.

The ā€œGUI:Clone()ā€ is already sat to the frame

local Players = game:GetService("Players")
local StarterScreen = Players.LocalPlayer.PlayerGui:WaitForChild("StarterScreen")
local gui = StarterScreen:WaitForChild("Frame")  --here it gets the frame
local TweenService = game:GetService("TweenService")


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

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		local MouseX = Mouse.X
		local MouseY = Mouse.Y
		local ToPosX = MouseX + math.random(-50, 50)
		local ToPosY = MouseY + math.random(-50, 50)
		local GuiClone = gui:Clone() -- Here it clones the frame
		
		local goal = {Position = UDim2.new(UDim.new(0, ToPosX), UDim.new(0, ToPosY))}
		
		local tweenInfo = TweenInfo.new(
			2,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
			)
		
		local tween = TweenService:Create(GuiClone.Frame, tweenInfo, goal)
		
		tween:Play()
	end
end) 

Ah, in that case, nevermins, just using GuiClone would be fine. If it still doesn’t work, I’ll have to read around to see what the problem is.

Sorry to disappoint, but it still does not work

No need to worry, I’m the one that’s been walking through this, the fault is mine. I’ll figure it out and get back to you when I can.

1 Like

Oh wow! you are the sweetest person on the planet mate. I appreciate you so much!

1 Like

Any new update on this??? @Zerovaskr