Mouse movement replay

I’m trying to make my mouse position store itself in a string value, and then move an image label into it’s old positions again. Here’s what I did:

Note: “MouseA” is the imagelabel

local Folder = Instance.new("Folder", workspace)
Folder.Name = "SavedPositions1"

local Mouse = game.Players.LocalPlayer:GetMouse()

local NumberBesideName = 0
local CurrentFrame = 0

Record.MouseButton1Up:Connect(function()
while wait(0.03) do
		NumberBesideName += 1

		local SavedMousePOS = Instance.new("StringValue", Folder)
		SavedMousePOS.Name = "SavedPositionMouse"..NumberBesideName
		SavedMousePOS.Value = Mouse.X..", "..Mouse.Y
		warn(SavedMousePOS.Value)
        end
end)

Play.MouseButton1Up:Connect(function()
	CurrentFrame = 0
	Playing = true
	while wait(0.03) do
		CurrentFrame += 1

		script.Parent.MouseA.Position = UDim2.new(tonumber(Folder:FindFirstChild("SavedPositionMouse"..CurrentFrame).Value))

The value cannot be turned into a Number as it has a comma in it, and a UDim2 needs 4 values, so you should do this:

local val = Folder:FindFirstChild("SavedPositionMouse"..CurrentFrame).Value:split(",")
script.Parent.MouseA.Position = UDim2.new(0, tonumber(val[1]), 0, tonumber(val[2]))
1 Like

Thank you so much for helping me! :slight_smile:

Slight optimisation but the tonumber() calls can be removed.

print(UDim2.new("1", 0, "1", 0)) --{1, 0}, {1, 0}