Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can Someone explain more in detail this code?

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

✓ Accepted answer

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.

1 comment

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.