I am trying to make a "staircase" tool that essentially allows the player to traverse anywhere in the sky. it basically puts blocks under the players feet continuously whenever the input is held down. That works fine, however, the issue i'm having is that the staircasing gets exponentially increased whenever i press another key due to the nature of the while loop. (The while loop persists and infinitely doubles up on itself everytime i give it new inputs).
I dont want that. How do i stop it from exponentially increasing and keep it at a constant generation speed whilst still allowing movement. In other words, how do i stop the while loop from stacking up on itself.
Thanks
local Tool = script.Parent
local UserInputService = game:GetService("UserInputService")
function holdTool(input,wasProcessed)
local flag = true
--if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) == true and flag then
while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) == true and flag do
print(input)
print(input.UserInputType)
local bodyPosition = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position
local flyingBit = Instance.new("Part",workspace.Flying_Pieces)
flyingBit.Size = Vector3.new(5,1,5)
flyingBit.CFrame = CFrame.new(bodyPosition.X,bodyPosition.Y-4,bodyPosition.Z)
wait(0.2)
--if UserInputService:GetKeysPressed then
--end
end
print("end")
end
function doNothing()
end
if Tool.Equipped then
UserInputService.InputBegan:Connect(holdTool)
UserInputService.InputEnded:Connect(doNothing)
end
Gif of the problem: https://gyazo.com/9132c0b102dd4d1d07f1d2f90c8347a8
