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

Decrementer not working, the clone doesn't get closer...???

So I have a cloned player, he is suppose to trail behind the players footsteps for 2 seconds and slowly get faster over time although, if I put in the loop,

velocityTime = velocityTime + 1

The clone stays still and absolutely nothing happens... Without it though, the clone is able to move...???

local plar = game.Players.LocalPlayer.Character:Clone()
wait(2)
local lastPositions = {}
local velocityTime = 200
spawn(function()
	while true do wait(.01) -- negative 100 for one second
		table.insert(lastPositions,tostring(game.Players.LocalPlayer.Character.HumanoidRootPart.Position))
	end
end)
plar.Parent = workspace
plar.Name = plar.Name.."_Clone"
plar.Humanoid.WalkSpeed = 8
spawn(function()
	while true do wait()
		if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position-plar.HumanoidRootPart.Position).Magnitude < 10 then
			plar.Humanoid:MoveTo(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
			lastPositions = {}
		else
			if lastPositions[#lastPositions-velocityTime] then
				local StringVector = lastPositions[#lastPositions-velocityTime]
				local tab = {}
				for s in string.gmatch(StringVector,"[^,]+") do
				    table.insert(tab,tonumber(s))
				end
				local NewVector = Vector3.new(unpack(tab))
				plar:SetPrimaryPartCFrame(CFrame.new(NewVector))
			end
		end
	end
end)

When I printed velocityTime it was decreasing but the player was frozen. If anyone can help, that would be great... It is a local script for localization

1 answer

✓ Accepted answer
  • I don't see a reason why you can't store the Position in lastPositions rather than a string representation of it
  • wait will wait for no less than ~0.03 seconds, so you won't get 100 per second in lastPositions
  • I think you've got some logic errors in your while loop, but I'm not 100% sure what you intend

Instead of lines 3-9 and 13+ you could do (for simplicity, not performance):

local localPlayer = game.Players.LocalPlayer
while true do
	wait()
	local root = localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart")
	local pos = root and root.Position
	if pos then
		delay(2, function()
			plar.Humanoid:MoveTo(pos)
		end)
	end
end

In that delay function, you could also have logic to see if you should teleport to pos instead of walking (ex if the cloned character is too far away).

3 comments

0

the clone teleports also, but delay will get what happened 2 seconds ago right?? That is what you are saying

0

Because the player teleports to places and I need the clone to follow where they go, the teleporters become unavailable after being touched

0

It worked, thanks man, this can make all my time scripts infinitely easier to code!!

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