Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I decrease the lag from this script?

Asked by 4 years ago
Edited 4 years ago

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?

1
Please use code block User#5423 17 — 4y
0
sorry, didn't know how to use it awesomecaysson 0 — 4y
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. SteelMettle1 394 — 4y
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 123nabilben123 499 — 4y
0
I edited the question to include the movement function. awesomecaysson 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question