I wrote a system that handles “Conveyor” tags, and animate textures on the client side. But after some time maybe 5-10 minutes textures clones itself, then it clones again after a while (The original texture keeps moving while the clone ones is staying still). The cloning step is before animating step so why does it clone itself?
Script in the server script service
--!strict
for _, v in game:GetService("CollectionService"):GetTagged("Conveyor") do
if v:IsA("BasePart") then
v.AssemblyLinearVelocity = v.CFrame.LookVector * v:WaitForChild("Speed").Value
end
end
local conveyorVal: IntValue = Instance.new("IntValue")
conveyorVal.Name = "ConveyorAmount"
conveyorVal.Value = #game:GetService("CollectionService"):GetTagged("Conveyor")
conveyorVal.Parent = game:GetService("ReplicatedStorage")
Script in the client side (parented to StarterGui directly)
--!strict
local oriTexture: Texture = game:GetService("ReplicatedStorage"):WaitForChild("ConveyorTexture")
local textureSpeed: {[Texture]: number} = {}
local conveyorsToLoad: number = game:GetService("ReplicatedStorage"):WaitForChild("ConveyorAmount").Value
while #game:GetService("CollectionService"):GetTagged("Conveyor") < conveyorsToLoad do
game:GetService("CollectionService"):GetInstanceAddedSignal("Conveyor"):Wait()
end
for _, v in game:GetService("CollectionService"):GetTagged("Conveyor") do
if not v:IsA("BasePart") or v:FindFirstChildOfClass("TextLabel") then return end
local newTexture: Texture = oriTexture:Clone()
newTexture.StudsPerTileU = v.Size.X
if v.Name == "Holder" then
newTexture.Transparency = 0.7
end
newTexture.Parent = v
textureSpeed[newTexture] = v:WaitForChild("Speed").Value
end
game:GetService("RunService").PreAnimation:Connect(function(deltaTimeSim: number)
for t, speed in textureSpeed do
t.OffsetStudsV = (t.OffsetStudsV - deltaTimeSim * speed) % 4
end
end)