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)
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)
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.
-- 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()
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)