The title says it all, with MouseButtonClick or UserInputService etc
2 Likes
You could use MouseButton1Down
ans MouseButton1Up
together, or user UserInputService
's InputBegan
and InputEnded
.
t.MouseButton1Down:Connect(function()
t.Text = 'down Click'
t.MouseButton1Up:Connect(function()
t.Text = 'up Click'
end)
end)
Something will happen if he holds it down, if he clicks it will be something else, here both happens, I need a single function that returns ‘hold’ or ‘click’
I’m on mobile right now so I can’t test this, but this is what I came up with:
t.MouseButton1Down:Connect(function()
t.Text = 'down Click'
-- Create a RunService event connection
local elapsedTime = 0
local connection = game:GetService("RunService").Stepped:Connect(function(_, delta)
elapsedTime += delta -- Add the time since the last frame to the elaspedTime variable
end)
t.MouseButton1Up:Wait() -- Wait for the event to fire
connection:Disconnect() -- Disconnect the event
t.Text = 'up Click'
if elaspedTime < 1 then
-- An example condition for checking if the user held down the button
-- 1 would be how much time that must be surpassed in order to say that the user held the button down
-- For this statement, the user just clicked the button
end
end)
If 1
is too long, just mess around with the value until it fits.
1 Like