Basically, When you are near the Part, and you hold E for 5 seconds, it should print "Hi" Everything works, im a bit confused at the runservice part
** dt = dt + game:GetService('RunService').RenderStepped:Wait();**
Can someone explain this more in depth pls?
UIS.InputBegan:Connect(function(Key, Process) if (Process) then return nil end; if (Key.KeyCode == Enum.KeyCode.E) then local dt = 0; while ( (part.Position - Humanoid.Position).magnitude < 10) and UIS:IsKeyDown(Key.KeyCode) do if (dt >= 5) then print("hi") break; end dt = dt + game:GetService('RunService').RenderStepped:Wait(); end end end)
Hey there.
So to begin with the keycode to press for the function to run, as you'd know, is E.
local dt
is just the variable for the amount of seconds the key is pressed for.
The next while
loop checks if the part's position is 10 studs away from the Humanoid'd position.
If it is, then the code carries on until the timer reaches 5 seconds, hence the:
dt = dt + game:GetService('RunService').RenderStepped:Wait();
Finally, if the timer reaches 5 or is greater than 5 seconds, the code stops.