I'm trying to make an ice trail where ice trails the players feet like a puddle constantly. The problem is that when I clone the ice trail as the player is moving, the trail just moves itself and doesn't keep on cloning but rather changes its position although I'm having it cloned from the Replicated Storage and the loop is a while true do loop. So I'm confused as to why the ice trail is not consistently cloning as the player moves but just changes position.
Here is the code, it's being fired through an event from StarterCharacterScripts, and this actual script is in ServerScriptService.
--Services-- local ReplicatedStorage = game.ReplicatedStorage local TweenService = game:GetService("TweenService") --Events-- local TrailEvent = ReplicatedStorage.IceTrailEvent --Obj-- local Trail = game.ReplicatedStorage:WaitForChild("Trail"):Clone() TrailEvent.OnServerEvent:Connect(function(player) local Character = player.Character local leftLeg = Character:FindFirstChild("LeftLowerLeg") local h = Character.Humanoid h.WalkSpeed = 50 while h.MoveDirection ~= Vector3.zero do print("left leg is moving") Trail.Parent = leftLeg Trail.Position = leftLeg.Position wait() end end)
I'm an amateur when it comes to scripting for those who wonder so that they can make their explanation detailed/less detailed for me to understand.
To constantly clone a part as the player is moving, you can call clone()
in the while-loop like so:
while h.MoveDirection ~= Vector3.zero do print("left leg is moving") local clone = Trail:Clone() -- New clone created clone.Parent = leftLeg clone.Position = leftLeg.Position wait() end
Please note that rapidly cloning parts on the server may cause lag. Also, latency will cause the cloned parts to appear behind the character. There is a fix for this, but it's much more involved if you still want other players to see the trail of parts. You can alternatively use the Trail object provided by Roblox.