Hi, I was trying to make a grid placement script and I made this script to run the placement:
UserInputService.InputChanged:connect(function(inputObj)
if (inputObj.UserInputType == Enum.UserInputType.MouseMovement) then
if build.Value == true then
Movement()
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local copy = Model:Clone()
copy.Parent = Model.Parent
copy:SetPrimaryPartCFrame(CFrame.new(PosX, PosY, PosZ))
end
end)
end
end
end)
Movement script :
local function Movement()
Mouse.TargetFilter = Model --Ignores the model
Snap() -- Gets the variables ready (We will snap later)
Model:SetPrimaryPartCFrame(CFrame.new(PosX, PosY , PosZ)) -- Moves the model
end
But using this script causes it to lag the game and even crash roblox studio. It outputs this error : 15:26:07.994 - RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Players.awesomecaysson.PlayerScripts.PlayerModule.CameraModule.ZoomController.Popper:248: Script timeout: exhausted allowed execution time
Using a while true do script didn't work (with wait()). Is there a way to decrease the chance of getting an error?

5 comments
Please use code block
sorry, didn't know how to use it
As a general rule, never have nested double-event-driven functions. What will happen is the second one will perform its tasks incrementally. In other words: move your InputEnded function outside of InputChanged.
awesomecaysson What does the function Movement() do? Maybe thats lagging it but I can't see what it does so you should include it too
I edited the question to include the movement function.