I have made a animated skin system for my game [ET [II]] which enables you to make textures move by increasing the stud offset. (ET [II] - Roblox)
There is a problem though, once skins are applied runjob in Microprofiler goes bonkers, making FPS decrease incredibly and frame time to go over the top.
Any way on how to proceed to fix this?
local i = 0
local c = 0
local i2 = 0.0045
local c2 = 0.0045
game:GetService("RunService").Heartbeat:Connect(function()
for i, tex in pairs(script.Parent:GetDescendants()) do
if tex:IsA("Texture") then
tex.OffsetStudsU = i
tex.OffsetStudsV = c
end
end
i = i + i2
c = c + c2
end)
Well, the issue definitely lies within you using a Heartbeat connection to handle this. Instead, you should probably use a tween so you can just tween the OffsetStudsU and OffsetStudsV without actually needing to do the math. The tween would look something like this:
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(166.67, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, -1)
for i, tex in pairs(script.Parent:GetDescendants()) do
if tex:IsA("Texture") then
TS:Create(tex, TI, {OffsetStudsU = 45, OffsetStudsV = 45}):Play()
end
end
You should probably adjust the EasingStyles to match what looks best, I donβt use textures so Iβm not sure.
Maybe try using mod instead of just adding to a decimal infinitely
runservice.Heartbeat:Connect(function()
for i,v in ipairs(script.Parent:GetDescendants()) do
if tex:IsA('Texture') then
tex.OffsetStudsU = i
tex.OffsetStudsV = c
end
end
i = (i + i2) % 1
c = (c + c2) % 1
end)
You will probably have to switch 1 to what ever your StudsPerTileU and V are though.
Another idea, check the amount of time that has passed since the last frame since you mentioned in game that itβs really only obvious with fps unlocker (assuming youβre updating it on the client):
runservice.Heartbeat:Connect(function(deltaTime)
if deltaTime < 0.0166 then -- 1/60
return
end
-- ...
end)