Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can Someone explain more in detail this code?

Asked by
Borrahh 265 Moderation Voter
4 years ago

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)

1 answer

Log in to vote
1
Answered by
o_fex 146
4 years ago

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.

0
Um, you explained what I knew already :/ as I said, i need the dt = dt + game:GetService('RunService').RenderStepped:Wait(); explained Borrahh 265 — 4y
Ad

Answer this question