local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart") local UIS = game:GetService("UserInputService") local Part = game.Workspace.GUIPart UIS.InputBegan:connect(function(KeyCode) if KeyCode.KeyCode == Enum.KeyCode.E then if (Part.Position - HumanoidRootPart.Position).magnitude < 20 then -- effect print("HI") end end end)
Try this:
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart") local UIS = game:GetService("UserInputService") local Part = game.Workspace.GUIPart local HoldCount = 0 UIS.InputBegan:connect(function(KeyCode) if KeyCode.KeyCode == Enum.KeyCode.E then if (Part.Position - HumanoidRootPart.Position).magnitude < 20 then while UIS:IsKeyDown(Enum.KeyCode.E) do wait(1) HoldCount = HoldCount + 1 If HoldCount == 5 then break -- this will automatically end after 5 seconds end end HoldCount = 0 -- Reset hold count -- effect print("HI") end end
Hope this helped! Best of luck developer.
BlackOrange3343
PS: If it doesn't work then comment the error