Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to smoothly duplicate a part on the players leg as the player moves?

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.

3 comments

0

The trail spawns on the players left lower leg by the way, if that is important to anyone's answer.

0

Can you paste your code? Hard to provide help to such a niche issue without seeing how exactly you are approaching the problem with your code. There are many ways to code the same exact thing. Also helpful in giving a little insight into your skill level, so we need how to word our answers without being too basic/detailed.

0

Done.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.