Basically, i have a setTime like 4 secs or smth. what i want to do is to wait for setTime's value such as wait for 4 secs. Then do sum stuff. Iam facing an issue tho.
I am using an if statement to check if a variable is tru or not and if it is it runs the wait(setTime) line. But i want to break the if statement value is changed mid-waiting.
So is there any better way to wait other than using the wait(). And also how do i check if the var is changed?
Code:
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
breaking = true
local secs = 4 --time to wait
if breaking then
wait(secs)
--do stuff here
end)
UserInputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
breaking = false
end)
yes because the variable being checked is global (outside the connection).
So if it changes before the wait time is up, when you re-check for the variable it will see that it is false and not true.
What iam trying to say is that i want to count from the time like 4 secs, if mid counting the var changed i want to break the if satatement? Any solutions?
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if not breaking then
breaking = true
local timeSpent = 0
repeat
timeSpent += 1
task.wait(1)
until not breaking or timeSpent >= 4
if timespent >= 4 then
-- do stuff
end
end
end
InputEnded:
if input.UserInputType == Enum.UserInputType.MouseButton1 then
breaking = false
end
For checking the variable changed you could just make a value somewhere and maybe use this:
coroutine.wrap(function()
while wait() do
[value].Value = variable
[value]:GetPropertyChangedSignal(“Value”):Connect(function()
–code
end)
end
end)()
My opinion is that it’s very simple and effective!