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

How do I decrease the lag from this script?

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

1

Please use code block

0

sorry, didn't know how to use it

1

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.

0

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

0

I edited the question to include the movement function.

1 answer

Answer found! I took out UserInputService.InputEnded:Connect(function(input) (like SteelMettle1 said) and just changed it with Mouse.Button1Down:Connect(function())

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