I am trying to make the wait time reset to 3.5 every time the mouse button is clicked whiles it is waiting.
For example:
local waitingtime = 3.5
mouse.Button1Down:Connect(function()
waitingtime = 3.5
end
end)
wait(waitingtime)
aim = true
But it does not work. How would I do this?
I am trying to make a third person aim system like GTA 5 where if you press mouse button and the wait time is at 2.5 the wait time will go back to 3.5
local waitingtime = 0
mouse.Button1Down:Connect(function()
mb1 = true
waitingtime = 3.5
if canaim.Value == true then
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local rx, ry, rz = Camera.CFrame:ToOrientation()
rootPart.CFrame = CFrame.new(rootPart.CFrame.p) * CFrame.fromOrientation(0, ry, 0)
aim = true
end
end)
mouse.Button1Up:Connect(function()
mb1 = false
wait()
waitingtime = 3.5
isrun.Changed:Connect(function()
if isrun.Value == true then
if mb2 == false then
if mb1 == false then
aim = false
end
end
end
end)
wait(waitingtime)
if mb2 == false then
if mb1 == false then
aim = false
end
end
end)
If you are confused about what I am talking about let me know.
You can define your function and a globally accessible variable and then decrement waiting_time in the script by dt, otherwise referred to as “delta time”, which in this case is referred to as the change in time between the time the wait() function is called and when the script continues after it has waited:
local waiting_time = 3.5
function custom_wait()
while (waiting_time > 0) do
waiting_time -= wait()
end
end
mouse.Button1Down:Connect(function()
waiting_time = 3.5
end)
custom_wait()
aim = true
I think I somewhat understand what you are trying to do. I wouldn’t say this is the best method, but this is just to give you a general idea :
local waitingtime = 3.5
mouse.Button1Down:Connect(function()
waittingtime = 3.5
end)
while waittingtime < 0 do
wait(.5)
waittingtime -= .5
end
This without a doubt is a pretty bad method, but I hope I gave you a good idea on what you have to do. There’s other things as well, such a coroutine wrap function. Which will allow you to have the loop, without interrupting the script
Yes, that gave me my answer thank you. Nevermind It does not work!!!
local waitingtime = 3.5
mouse.Button1Down:Connect(function()
waittingtime = 3.5
end)
while waitingtime >=0.1 do
waitingtime =waitingtime - .1
wait(0.1)
print(waitingtime)
end
if waitingtime <= 0 then
aim = true
end