I can't modify cloned instance

This is a code of teleport button in local script, but I can’t modify this instance.

local TeleportButton = Instance.new("TextButton")

for i, v in pairs(game.Workspace:GetChildren()) do
    if not v:IsA("Part") then
        continue
    end
    TeleportButton:Clone().Parent = LocalPlayerGUI.ScrollingFrame
    TeleportButton.Text = v.Name
    TeleportButton.MouseButton1Click:Connect(function() 
        game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Workspace[v].CFrame end)
	end
2 Likes

You need to store the clone in a variable so the code would look something like this

local button = TeleportButton:Clone()
button.Parent = LocalPlayerGUI.ScrollingFrame
button.Text = v.Name
button.MouseButton1Click:Connect(function() 
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Workspace[v].CFrame end)
end
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.