Script attached to Cloned part is not working

I have a local script in the StarterPlayerScripts folder that checks if the player is moving. If the player is moving, then it clones a part from ReplicatedStorage and places it in the workspace right behind the player. This creates a nice trail behind the player as they walk/run (like the cycles in TRON)

The part that is replicated has an attached script that will make it fade away over time. I have tested this by placing the part in the workspace directly and it works perfectly. However the same part and script does not work if its is cloned. It appears in the workspace as expected but the script attached to it does nothing. I have checked the part AND script are being cloned.

Thanks for any guidance,
rich

Script on the part:

local Trail = script.Parent
for thisTrans = 0,1,.01 do
Trail.Transparency=thisTrans
wait(.1)
end

local script on the play:

local RunService = game:GetService(“RunService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local trail= ReplicatedStorage.Trail
local Players = game:GetService(“Players”)
local localPlayer = Players.LocalPlayer

local function updateTrailEffect()
if localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.WalkSpeed=25
if humanoid.MoveDirection.Magnitude > 0 then
local humanoidRootPart = localPlayer.Character:WaitForChild(“HumanoidRootPart”)
local ThisTrail=trail:Clone()
ThisTrail.Parent = game.Workspace.PlayerTrails
local offsetCFrame = CFrame.new(0, 0, 3)
ThisTrail.CFrame = humanoidRootPart.CFrame:ToWorldSpace(offsetCFrame)
end
end
end
wait()
return true

end

while updateTrailEffect() do
wait()
end

Screenshot of my setup:

The script in the part is a server script, yet it is cloned by a local script. Server script run on the server, not the client. This means that when placed directly into workspace from studio, this is done to the server so it can run. But when done locally, it is only done on the client and the server script cannot run, you’ll have to either clone it on the server or use a local script to make it dissapear.

3 Likes

you can try:
local trail = game.ReplicatedStorage.Trail:Clone()
trail.Parent = game.Worksapce

No. That is not how this will work. You need to use a remote event to make the server do the cloning rather than the localscript.

He said his problem was with the local script destroying the part after a while, not the parts failing to clone