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.
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.
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
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.
Oh wow! you are the sweetest person on the planet mate. I appreciate you so much!