Repeat() speeding up each time?

Hi, I’m currently working on a show case that lines up the next Model, inserts it etc.
However, for whatever reason when you switch between the different categories in-game the transition between each models seems to speed up, increasing each time.

https://gyazo.com/2ab568863eee0a513a243ae0668a6e89
The full code is below, Please do ignore my layout of coding - It’s simply my chosen method as it helps with my dyslexia.

repeat wait(.01) until workspace.Camera ~= nil

--||--||--||--||--

local Storage =

{Player = game.Players.LocalPlayer,

Camera = workspace["Camera"],

DisplayModel = workspace["Display"],

Objs = game.ReplicatedStorage:WaitForChild("Objs")}

local isDisplayed =

{Seekling = false,

Building = false,

Misc = false}

local DisplayValues =

{CurrentSeekling = 1}

local MaxSeekling = Storage.Objs["Seeklings"]:GetChildren()

--||--||--||--||--

--||--||--||--||--

local ViewPoint01 = Storage.DisplayModel["ViewPoint01"]

Storage.Camera.CameraType = "Scriptable"

Storage.Camera.CFrame = CFrame.new(ViewPoint01.CFrame.p + ViewPoint01.CFrame.LookVector * 15, ViewPoint01.CFrame.p)

local Gui = script["SelectionGui"]:Clone()

Gui.Parent = Storage.Player["PlayerGui"]

Gui["Frame"]["Seekling"].MouseButton1Down:Connect(function()

if isDisplayed.Seekling == false then else return end

isDisplayed.Seekling, isDisplayed.Building, isDisplayed.Misc = true, false, false

ValuesChanged()

return

end)

Gui["Frame"]["Building"].MouseButton1Down:Connect(function()

isDisplayed.Seekling, isDisplayed.Building, isDisplayed.Misc = false, true, false

ValuesChanged()

end)

Gui["Frame"]["Misc"].MouseButton1Down:Connect(function()

isDisplayed.Seekling, isDisplayed.Building, isDisplayed.Misc = false, false, true

ValuesChanged()

end)

--||--||--||--||--

--||--||--||--||--

function ValuesChanged()

for _,CheckDisplay in pairs (Storage.DisplayModel["OnDisplay"]:GetChildren()) do

if CheckDisplay then CheckDisplay:remove()

else end

end

--||--

if isDisplayed.Seekling == true then

DisplayValues.CurrentSeekling = 1

repeat wait()

Storage.Camera.CFrame = CFrame.new(Storage.DisplayModel.SpawnPoint.CFrame.p + Vector3.new(0, 2, 0) - Storage.DisplayModel.SpawnPoint.CFrame.LookVector * 5)

for _,CheckDisplay in pairs (Storage.DisplayModel["OnDisplay"]:GetChildren()) do

if CheckDisplay then CheckDisplay:remove()

else end

end

local ToDisplay = Storage.Objs["Seeklings"][DisplayValues.CurrentSeekling]:Clone()

ToDisplay.PrimaryPart = ToDisplay["Base"]

ToDisplay:SetPrimaryPartCFrame(CFrame.new(Storage.DisplayModel.SpawnPoint.CFrame.p) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), math.rad(-90)))

ToDisplay["Seekling"]["Head"]["Face"]["Decal"]:remove()

ToDisplay.PrimaryPart.Transparency = 1

ToDisplay.Parent = Storage.DisplayModel["OnDisplay"]

wait(1)

if DisplayValues.CurrentSeekling == #MaxSeekling then DisplayValues.CurrentSeekling = 1

else

DisplayValues.CurrentSeekling = DisplayValues.CurrentSeekling+1

end

until

isDisplayed.Seekling == false

else return end

--||--

end
2 Likes

It doesn’t look like it’s speeding up, it looks more like assets missing and loading for the first time. Perhaps you should look into using ContentProvider.PreloadAsync on your characters somewhere in ReplicatedFirst and see if that changes the “speed”.

A note as well - I see that you’re using Object:remove(). Remove was deprecated a while ago and isn’t recommended for use (the method is just an alias for Object.Parent = nil). You should switch to Destroy. This disconnects all connections and prepares the object for garbage collection (and thus doesn’t take a hit on your server memory).

4 Likes