Animated texture clones itself after a couple of minutes

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)
1 Like

it will be something to do with oriTexture:Clone(), not sure what tho

1 Like

I don’t think so because textures only animate after it passes the :Clone() section

1 Like

This seems like the issue, if the character respawns. PlayerGui gets repopulated every time the player resapwns, causing scripts in there to be re-ran. I think this should live in StarterPlayer>StarterPlayerScripts instead.

I also think that you should re-write this code to have a single function to hookup a conveyor. And then call this function for all existing conveyors, and then call it for new conveyors that are added.

local CollectionService = game:GetService('CollectionService')
local CONVEYOR_TAG = "Conveyor"
function hookupConveyor(conveyorPart)
	-- code here
end
for _,conveyorPart in CollectionService:GetTagged(CONVEYOR_TAG) do
	task.spawn(function()
		hookupConveyor(conveyorPart)
	end)
end
CollectionService:GetInstanceAddedSignal(CONVEYOR_TAG):Connect(hookupConveyor)
2 Likes

I tried printing everytime it passes through animate section and it does really reanimate every character death, Thank you!

2 Likes